Results 1 to 3 of 3
  1. #1
    5 Star Lounger bfxtrfcmgr's Avatar
    Join Date
    Aug 2002
    Location
    Fresno, California, USA
    Posts
    995
    Thanks
    12
    Thanked 0 Times in 0 Posts

    No data form (2002)

    First, sorry for the "subject" title; I didn't know what to call this issue.

    The following code is in a command button on a form that calls another form. The link criteria requires that an entry be made for cboClass in the originating form in order for the second form to open with data. If no entry is made in cboClass, the form does open, but it's just blank. What would be the "right" way to deal with this? I was thinking that the code should look for an entry in cboClass and, finding none, display a msg (i.e. You must first select a class before choosing this option"), set focus on cboClass, and also prevent the second form from opening at all. Any help appreciated (there are three other command buttons that would require similar treatment).
    <pre>Private Sub cmdClass_Click()
    On Error GoTo Err_cmdClass_Click

    Dim stDocName As String
    Dim stLinkCriteria As String

    stDocName = "frmClassesView"

    stLinkCriteria = "[txtClassNo]=" & "'" & Me![cboClass] & "'"
    DoCmd.OpenForm stDocName, , , stLinkCriteria

    Exit_cmdClass_Click:
    Exit Sub

    Err_cmdClass_Click:
    MsgBox Err.Description
    Resume Exit_cmdClass_Click

    End Sub</pre>


    EDIT: After spending an hour or so struggling with this, and then making this post, I "stumbled" across something that works. It may not be very eloquent, but it does work! Sorry for the bother.
    <pre>Private Sub cmdClass_Click()
    On Error GoTo Err_cmdClass_Click

    Dim stDocName As String
    Dim stLinkCriteria As String

    stDocName = "frmClassesView"

    If IsNull(Me.cboClass) Then
    MsgBox "You must first select a class for this stident.", vbInformation
    Me.cboClass.SetFocus
    Exit Sub
    End If

    stLinkCriteria = "[txtClassNo]=" & "'" & Me![cboClass] & "'"
    DoCmd.OpenForm stDocName, , , stLinkCriteria

    Exit_cmdClass_Click:
    Exit Sub

    Err_cmdClass_Click:
    MsgBox Err.Description
    Resume Exit_cmdClass_Click

    End Sub</pre>

    Bryan,
    Not the smartest critter on the glacier. . .
    . . .but I'm persistent (does that count?)

  2. #2
    Gold Lounger
    Join Date
    Jun 2001
    Location
    Crystal Beach, FL, Florida, USA
    Posts
    3,436
    Thanks
    1
    Thanked 34 Times in 34 Posts

    Re: No data form (2002)

    There is nothing wrong with your solution. That is exactly what anyone here would have suggested. Although, we might have used "student" instead of "stident"! <img src=/S/wink.gif border=0 alt=wink width=15 height=15>
    Mark Liquorman
    See my website for Tips & Downloads and for my Liquorman Utilities.

  3. #3
    5 Star Lounger bfxtrfcmgr's Avatar
    Join Date
    Aug 2002
    Location
    Fresno, California, USA
    Posts
    995
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Re: No data form (2002)

    <img src=/S/blush.gif border=0 alt=blush width=15 height=15>. . .now you know why I can't write code.
    Thanks Mark.
    Bryan,
    Not the smartest critter on the glacier. . .
    . . .but I'm persistent (does that count?)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •