View Full Version : Form Filed Validation


DanG
05-28-2008, 12:03 PM
I suck at VBA, but I'm still trying to work my way through it.

I can not get this code to work...

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

RuralGuy
05-28-2008, 01:44 PM
HOw about something like:
If IsDate(Me.OBusDMAprvlDate) Then
If Len(Me.OBusHOName & "") = 0 Then
MsgBox ("Fill in your name dummy")
End If
Else
MsgBox ("Hello")
End IfIn what event are you putting this code?

DanG
05-28-2008, 02:42 PM
Hi RG,

That seemed to do it...thank you very much.
I am using the OnCurrent event.
If I may ask..

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:

georgedwilkinson
05-28-2008, 03:00 PM
If the OBusHOName is null, the "" makes the overall value = "" (NULL & "" = "").

RuralGuy
05-28-2008, 03:00 PM
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.

DanG
05-28-2008, 03:19 PM
Thanks guys!
You learn something new every day and it only hurts a little.

RuralGuy
05-28-2008, 05:21 PM
Glad we could help.