Paul, yes you are correct, and I did what you suggested, and it worked. If I
enter one date without the other my message appears and the secondary form
does not open. However, now the rest of my form does not work properly. If I
enter criteria into any other field on the form the secondary form will not
open. Instead I get my message box.

Please help! Anyone... if you can.
:
It looks to me as though you want to run the first two parts of code
regardless of the date part. Is this right? If so, simply insert an 'Exit
Sub' line in your code...
-----
If Not IsNull(txtAddDateBegin) And Not IsNull(txtAddDateEnd) Then
strWhere = strWhere & " AND AddDate between #" & txtAddDateBegin & "#
and #" & txtAddDateEnd & "#"
Else
DoCmd.CancelEvent
Beep
MsgBox "Please enter both dates", vbInformation, "Incomplete Search
Criteria"
Exit Sub 'This exits the function and your openform code does not
run
End If
Cheers
:
Paul,
Thanks that's a great suggestion. Do you have any idea as to how I can keep
my secondary form from opening if the criteria is not met? Right now the
secondary form opens anyway because my Open Form code is separate from my
criteria code. This is because I have multiple fields included in my search
form. See the code below for what I mean.
*****CODE******
'Build the wherecondition to use in the OpenObject method.
If Not IsNull(txtTxPrID) Then
strWhere = strWhere & " AND TxPrID = " & txtTxPrID
End If
If Not IsNull(txtSSN) Then
strWhere = strWhere & " AND SSN Like " & "'*" & txtSSN & "*'"
End If
If Not IsNull(txtAddDateBegin) And Not IsNull(txtAddDateEnd) Then
strWhere = strWhere & " AND AddDate between #" & txtAddDateBegin & "#
and #" & txtAddDateEnd & "#"
Else
DoCmd.CancelEvent
Beep
MsgBox "Please enter both dates", vbInformation, "Incomplete Search
Criteria"
End If
'Open Form based on the contents of strSQL.
stDocName = "empfrmTaxPayerInfo"
DoCmd.OpenForm stDocName, , , strSQL
*****END CODE*****
:
Shel,
You may want to add something like this to not only check for Nul values,
but also for start dates that are greater than the end date....
--------------------
If [txtAddDateBegin] > [txtAddDateEnd] Then
MsgBox "You entered a Start Date that is later than the end date." &
vbCrLf & " " & vbCrLf & "Please select an earlier Start Date.",
vbExclamation, "Error..."
Exit Sub
ElseIf Not IsNull([txtAddDateBegin]) And IsNull([txtAddDateEnd]) Then
MsgBox "You must enter an End Date to begin search", vbExclamation,
"Error..."
Exit Sub
ElseIf IsNull([txtAddDateBegin]) And Not IsNull([txtAddDateEnd]) Then
MsgBox "You must enter a Start Date to begin search", vbExclamation,
"Error..."
Exit Sub
ElseIf IsNull([txtAddDateBegin]) And IsNull([txtAddDateEnd]) Then
MsgBox "You must enter a Start and End Date to begin search",
vbExclamation, "Error..."
Exit Sub
End If
--------------------------
Cheers
:
Scenario: The code below allows me to enter a date range and return only the
records that fit within the range. This works fine with both dates entered.
Problem: If either the txtAddDateBegin or txtAddDateEnd is left blank while
the other is filled in, I get all records.
What I want: Instead of all records I’d like code that will determine if
either of the fields is filled in and the other is not, then a message box to
appear. I’ve searched the knowledge base and tried a variety of if/then
combinations and can’t figure this out. Please HELP!
*************CODE *********
If Not IsNull(txtAddDateBegin) And Not IsNull(txtAddDateEnd) Then
strWhere = strWhere & " AND AddDate between #" & txtAddDateBegin & "# and #"
& txtAddDateEnd & "#"
End If
*************END CODE *********