vexing
09-15-2000, 02:58 PM
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?
Pat Hartman
09-16-2000, 05:12 PM
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.
vexing
09-19-2000, 10:22 AM
doesn't work....I tweaked it every way I know of (I am not experienced with Code) Message box never comes up...
Pat Hartman
09-19-2000, 11:27 AM
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.
vexing
09-19-2000, 12:01 PM
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
Pat Hartman
09-20-2000, 05:57 PM
Put quotes around the variable values and add the Me. qualifier to the control names:
If Me.Action = "other" Or Me.Problem = "other" Then
vexing
09-26-2000, 08:26 AM
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...
Pat Hartman
09-26-2000, 10:14 AM
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
vexing
09-27-2000, 10:24 AM
Thank You so much for all of your help! It is working now...