Problem with If Then...

Sausagefingers

Registered User.
Local time
Today, 15:17
Joined
Dec 14, 2006
Messages
51
Hi,
I'm trying to write a Sub which is to display a message box should a particular field be null as a user tabs through the form. The control itself is on a subform as you can see from the supplied example code below.

I have a feeling that 'Null' is an incorrect property but I'm also uncertain about the If Then format I am using.

You may have guessed by the simplicity of my question that I'm rather new to VB. I would appreciate some guidance in order to coax this rather shy message box to appear when it's supposed to! :confused:

Thanks In Advance


'------------------------------------------------------------
' orderNumber1_Exit
'
'------------------------------------------------------------
Private Sub orderNumber1_Exit(Cancel As Integer)
On Error GoTo orderNumber1_Exit_Err

If (Forms!frm_process!frm_orderDeliveryNumbers2!orderNumber1 = Null) Then

Beep
MsgBox "Supply a valid Purchase Order Number. If no Order Number exists, select 'NONE' from the Order Number listbox.", vbInformation, "..."
DoCmd.Requery ""

orderNumber1_Exit_Exit:
Exit Sub

orderNumber1_Exit_Err:
MsgBox Error$
Resume orderNumber1_Exit_Exit

End If
End Sub
 
Try the IsNull function

if IsNull(Forms!FormName!SubForm!Control)=True then
 
also I think you need an Else in there after the Exit Sub

Brian
 
One small Issue...

Thanks for your quick response guys. I have taken the advice from both replies and although I have the Sub working now, I was expecting 'DoCmd.Requery "" ' to requery the field. It doesn't so I must have some kind of error to contend with.

What I would like to happen if for the cursor to remain in the the orderNumber1 field once the messageBox is dismissed. It is moving to the next field. Any suggestions??

Thanks again :)
 
Use

Canel=True

if you want to stay in the field. Why do you want to requery?
 

Users who are viewing this thread

Back
Top Bottom