If Combo box is null

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. 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
 
J

John Malone

Wouldn't be easier to use "Validation"?

--
John Malone
==============
| 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. 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
 
R

Ronx

Try changing
If Forms![Create_AAR_Report]![ComboPriorPeriod_Date] = Null Then
to
If Forms![Create_AAR_Report]![ComboPriorPeriod_Date] = "" Then

A <select> <option> value will be an empty string, rather than null.
 
G

Guest

Hi John,

Validation would not work as I am using a case statement based off another
combobox to decide which report to run. Only one of the reports requires
that ComboPriorPeriod_date have a value.

Jones
 
G

Guest

Ronx,

I tried your adjustment with no luck. I put a watch on the combo box and
the value associated with the box is Null. I am not sure what is going on.
In therory the statement should work.

Jones

Ronx said:
Try changing
If Forms![Create_AAR_Report]![ComboPriorPeriod_Date] = Null Then
to
If Forms![Create_AAR_Report]![ComboPriorPeriod_Date] = "" Then

A <select> <option> value will be an empty string, rather than null.
--
Ron Symonds - Microsoft MVP (FrontPage)
Reply only to group - emails will be deleted unread.
FrontPage Support: http://www.frontpagemvps.com/

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. 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

Top