Force entry in a field if value of other field = "x"

vexing

Registered User.
Local time
Today, 22:12
Joined
Sep 15, 2000
Messages
15
2 of the fields in my form are combo boxes with set choices. I want to force the user to put notes in the "Notes" field if
they choose the "other" option from either field. If have tried various macros, events, etc. I can't seem to get it right. Can
anyone give me a few pointers or a bit of sample code for an event or steps in a macro?
 
In the BeforeUpdate Event of the FORM place code similar to:

If IsNull(Me.NotesFld) Then
If Me.Fld1 = "Other" or Me.Fld2 = "Other" Then
MsgBox "some message, Update will be cancelled", vbOKOnly
Me.NotesFld.SetFocus
Cancel = True
End If
End If

The code tests to see if the notes field is empty. If it is, it checks fld1 and fld2 to see if either = "Other". If either does, it displays a message, sets the focus to the notes field, and cancels the update.

Make sure the message makes it clear that the record will not be saved.
 
doesn't work....I tweaked it every way I know of (I am not experienced with Code) Message box never comes up...
 
I'm very good. And sometimes I can debug code without seeing it. But, not this time. Please post the code if you would like further help.
 
Thanks, here it is:

Private Sub Form_BeforeUpdate(Cancel As Integer)
If IsNull(Me.Notes) Then
If Action = other Or Problem = other Then
MsgBox "If you choose 'Other' you must enter details in the 'Notes' field.", vbOKOnly
Me.Notes.SetFocus
Cancel = True
End If
End If
End Sub
 
Put quotes around the variable values and add the Me. qualifier to the control names:

If Me.Action = "other" Or Me.Problem = "other" Then
 
actually, I already tried that, and it didn't work; so I just took that stuff off to fiddle with it. I just put it back on, though, and it still doesn't work. I do not get prompted at all when I choose "other". It just lets me right through...
 
Using other without quotes should produce a syntax error. If it didn't, change your options so that Option Explicit is specified.

Did you try stepping through the code with the debugger so you could see the values in the three fields?

I guess it's possible that there are spaces in the NotsFld so try this:
If IsNull(Trim(Me.NotesFld)) Then
 
Thank You so much for all of your help! It is working now...
 

Users who are viewing this thread

Back
Top Bottom