Form Filed Validation

DanG

Registered User.
Local time
Today, 08:32
Joined
Nov 4, 2004
Messages
477
I suck at VBA, but I'm still trying to work my way through it.

I can not get this code to work...
Code:
If IsNull(Me.OBusDMAprvlDate) = False And IsNull(Me.OBusHOName) = True Then
    MsgBox ("Fill in your name dummy")
Else
    MsgBox ("Hello")
End If

If "OBusDMAprVlDate" has a date in it I want to make "OBusHOName" to be required, otherwise no entry required for either field.

I have tried several combinations and no luck. :confused:

Thank you
 
HOw about something like:
Code:
If IsDate(Me.OBusDMAprvlDate) Then
   If Len(Me.OBusHOName & "") = 0 Then
      MsgBox ("Fill in your name dummy")
   End If
Else
    MsgBox ("Hello")
End If
In what event are you putting this code?
 
Hi RG,

That seemed to do it...thank you very much.
I am using the OnCurrent event.
If I may ask..
Code:
Len(Me.OBusHOName & "")

What is the "" part do? I assume it conts the len if there is nothing in the field but I just don't quite get it. :confused:
 
It concantenates a ZeroLengthString (ZLS) to whatever is in OBusHOName. This covers both conditions where OBusHOName is a ZLS and OBusHOName is Null. BTW you are probably going to want to use the BeforeUpdate event of the form rather than the Current event. Then you can set Cancel = True to hold up the update until you have a name. The Current event occurs as soon as you get to the record before the user has had a chance to do anything.
 
Thanks guys!
You learn something new every day and it only hurts a little.
 

Users who are viewing this thread

Back
Top Bottom