If Then Statement in Click Event

G

Guest

I'd like to use an "If" statement in the click event of a button - If the
user doesn't fill in fields on the form before clicking the button, a message
instructs them.
This is what I tried. My error keeps asking for an object. Can someone
help me please?
*********************************
Private Sub openSupplierReport_Click()
On Error GoTo Err_Command2_Click

If(forms!SubMenuA.RawPNDDList is null) then
MsgBox "Please select a Part Number"

ElseIf (Forms!SubMenuA.BegDate is null) then
MsgBox "Please enter a Beginning and Ending Date"

ElseIf (Forms!SubMenuA.EndDate is null) then
MsgBox "Please enter a Beginning and Ending Date"

Else
Dim stDocName As String
stDocName = "rptReceiveFromSupplierData"
DoCmd.OpenReport stDocName, acPreview

end if

Exit_openSupplierReport_Click:
Exit Sub

Err_Command2_Click:
MsgBox Err.Description
Resume Exit_Command2_Click

End Sub
*************************************************
 
R

Rob Parker

The problem is with the way you are testing for a null. Instead of

If(forms!SubMenuA.RawPNDDList is null) then

you need

If IsNull((forms!SubMenuA.RawPNDDList) Then

etc.

HTH,

Rob
 

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