Here is a variation of karatelung's suggestion with some added features. I use this on a command button to open a report based on the beginning and ending date entered into two text boxes.
Private Sub cmdSelect_Click()
Dim bProcOk As Boolean
bProcOk = True
' The following IF Then series checks for null values in
' the start txtbox. If a null is found the error message
' is displayed and the focus is sent back to form control
If IsNull(Me.txtBeginDate) Then
MsgBox "You must provide a beginning date!", vbExclamation, "Error"
txtBeginDate.SetFocus
bProcOk = False
Else
If IsNull(Me.txtEndDate) Then
MsgBox "You must provide a ending date!", vbExclamation, "Error"
txtEndDate.SetFocus
bProcOk = False
End If
End If
If bProcOk Then ' If the above IF Thens are satisfied
' the following command is carried out
DoCmd.OpenReport "EmpContactLog", acPreview, , _
"[date]>=#" & Me![txtBeginDate] & "# And [date]<= #" & _
Me![txtEndDate] & "#"
' Opens the report based on the begin and end date
End If
End Sub