Problem with If statement and combo box value

G

Guest

Hi Everybody,

I am trying to write a bit a code that will pop up a msgbox if no selection
is made in the combo box. It does not appear to be recognizing that the
value of the combo box is null. Validation will not work as this is in a
case statement that decides which report to produce based on a selection in
another combo box. Here is what I have written so far.

Dim stDocName As String
Dim stDocName2 As String
Dim msg

msg = "For this type of report you must fill in the prior period date
box."
stDocName = "Macro_RunSQL_CreateAARReport"
stDocName2 = "Macro_RunSQL_CreateAARReport_C+P"

If Forms![Create_AAR_Report]![ComboPriorPeriod_Date] = Null Then
MsgBox (msg)
Exit Sub
Else
DoCmd.RunMacro stDocName2
DoCmd.OpenReport "AAR_Type4", acViewPreview 'Thompsnon
End If

Any clues to what I have done wrong?


Jones
 
G

Guest

Hi.

Change this:
If Forms![Create_AAR_Report]![ComboPriorPeriod_Date] = Null Then

To this:
If IsNull(Forms![Create_AAR_Report]![ComboPriorPeriod_Date]) Then

Think of "Null" as "Unknown". You can't make a comparison to an unknown
(your If statement), but you can test to find out whether something is
unknown (my If statement).

Of course, it is also possible that the control you are testing is not Null,
but rather an empty string, in which case you'd want to test for that as
well. For more info on this kind of issue, see:
http://allenbrowne.com/casu-11.html
http://allenbrowne.com/casu-12.html

-Michael
 
G

Guest

Michael,

Spot on with that response, thanks for the help

Michael H said:
Hi.

Change this:
If Forms![Create_AAR_Report]![ComboPriorPeriod_Date] = Null Then

To this:
If IsNull(Forms![Create_AAR_Report]![ComboPriorPeriod_Date]) Then

Think of "Null" as "Unknown". You can't make a comparison to an unknown
(your If statement), but you can test to find out whether something is
unknown (my If statement).

Of course, it is also possible that the control you are testing is not Null,
but rather an empty string, in which case you'd want to test for that as
well. For more info on this kind of issue, see:
http://allenbrowne.com/casu-11.html
http://allenbrowne.com/casu-12.html

-Michael



Jones Barton said:
Hi Everybody,

I am trying to write a bit a code that will pop up a msgbox if no selection
is made in the combo box. It does not appear to be recognizing that the
value of the combo box is null. Validation will not work as this is in a
case statement that decides which report to produce based on a selection in
another combo box. Here is what I have written so far.

Dim stDocName As String
Dim stDocName2 As String
Dim msg

msg = "For this type of report you must fill in the prior period date
box."
stDocName = "Macro_RunSQL_CreateAARReport"
stDocName2 = "Macro_RunSQL_CreateAARReport_C+P"

If Forms![Create_AAR_Report]![ComboPriorPeriod_Date] = Null Then
MsgBox (msg)
Exit Sub
Else
DoCmd.RunMacro stDocName2
DoCmd.OpenReport "AAR_Type4", acViewPreview 'Thompsnon
End If

Any clues to what I have done wrong?


Jones
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top