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>




