required field

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am trying to write messages to prompt the user for required fields if a
certain value is entered in a field. Should these messages be placed within
the form's close event? One example is if Status_Code = Active, then
Contract_Execution_Date must be entered. Here's what I tried and it did not
work:

If Me.Status_Code = "Active" And Me.Contract_Execution_Date Is Null Then
MsgBox "Please enter a Contract Execution Date"
End If

Also, Status_Code is required for new records - is there a way I can create
my own message box to replace the one Access automatically displays on close?
I just want it to read a little clearer for the users.

Thanks!
 
Lori wrote in message
I am trying to write messages to prompt the user for required fields
if a certain value is entered in a field. Should these messages be
placed within the form's close event? One example is if Status_Code
= Active, then Contract_Execution_Date must be entered. Here's what
I tried and it did not work:

If Me.Status_Code = "Active" And Me.Contract_Execution_Date Is Null
Then MsgBox "Please enter a Contract Execution Date"
End If

Also, Status_Code is required for new records - is there a way I can
create my own message box to replace the one Access automatically
displays on close? I just want it to read a little clearer for the
users.

Thanks!

I think such should probably be placed in the forms before update
event.
This event triggers just before the save operation is performed, and
you
can cancel it. The Null test you use, is the one used in SQL, for form
controls, one need either the IsNull function, or perhaps something
like
this

If Me.Status_Code = "Active" And _
len(Me.Contract_Execution_Date & vbNullString) = 0 Then
MsgBox "Please enter a Contract Execution Date"
Cancel = True ' <- cancels the save operation
End If

I think that if you use the forms before update event, you will
probably not need to substitute the default messages, but if you should
need, I think you can find them in the forms on error event.

if DataErr = <some number> then
msgbox "your custom message"
response = acdateerrcontinue ' cancels the default message
end if

To find the correct number to track for, use MsgBox DataErr within the
form error event, trigger you error, then substitute the <some number>
part.
 
Back
Top