Required fields

C

consjoe

I am makeing three fields required for the form, Company, State, and Date
Fine Paid. If all three are not blank then the macro is ran, if one or all
of them are blank the user recieves this message: Please Enter Required Field
(Company, State, and Date Fine Paid)!
My problem is VB doesn't like my Date Fine Paid field. I beleive it is
because it has spaces in it. It runs fine I just use company and state, but
gives me an error when I add Date Fine Paid. Compile Error Expected: )
I trided "" like "Date Fine Paid" but that didn't work.
Any ideas?
Thanks

If (Company.Value <> "" And State.Value <> "" And Date Fine Paid.Value
<> "") Then

Dim stDocName As String

stDocName = "New Fine Added"
DoCmd.RunMacro stDocName

Else: MsgBox "Please Enter Required Field (Company, State, and Date Fine
Paid)!"
End If
 
O

Ofer

You need to filter on Null also, also when you have a field with seperate
words you need to put it in brackets [Field Name]

If (Company.Value <> "" and not isnull(Company.Value) And State.Value <> ""
And not isnull(State.Value) And me.[Date Fine Paid].Value <> "" And not
isnull(me.[Date Fine Paid].Value) Then
 
A

Allen Browne

Put square brackets around the field that has spaces in its name.

You need to check for Null rather than a zero-length string.

You probably want Or rather than And (i.e. so the code runs if any one is
blank).

Presumably this is in the BeforeUpdate event procedure of your *form* (not
the event of a control.)

Try:
If IsNull(Me.Company) Or IsNull(Me.State) Or IsNull(Me.[Date Fine Paid])
Then
MsgBox "Bad data"
Else
...
 
C

consjoe

Thank You both.
I was using AND because it was running the macro if Company AND State AND
Date were not blank. If one of them was blank then it gave the message box.
I think I Like your way better though.
Thanks Again.

Allen Browne said:
Put square brackets around the field that has spaces in its name.

You need to check for Null rather than a zero-length string.

You probably want Or rather than And (i.e. so the code runs if any one is
blank).

Presumably this is in the BeforeUpdate event procedure of your *form* (not
the event of a control.)

Try:
If IsNull(Me.Company) Or IsNull(Me.State) Or IsNull(Me.[Date Fine Paid])
Then
MsgBox "Bad data"
Else
...

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

consjoe said:
I am makeing three fields required for the form, Company, State, and Date
Fine Paid. If all three are not blank then the macro is ran, if one or
all
of them are blank the user recieves this message: Please Enter Required
Field
(Company, State, and Date Fine Paid)!
My problem is VB doesn't like my Date Fine Paid field. I beleive it is
because it has spaces in it. It runs fine I just use company and state,
but
gives me an error when I add Date Fine Paid. Compile Error Expected: )
I trided "" like "Date Fine Paid" but that didn't work.
Any ideas?
Thanks

If (Company.Value <> "" And State.Value <> "" And Date Fine Paid.Value
<> "") Then

Dim stDocName As String

stDocName = "New Fine Added"
DoCmd.RunMacro stDocName

Else: MsgBox "Please Enter Required Field (Company, State, and Date
Fine
Paid)!"
End If
 
Top