Require fields

J

Jessica

I have two fields one call exit date and the other one exit reason. If a date
is enter in the exit date field i want the exit reason to be a require field.
How can i do that
 
B

Beetle

In the forms Before Update event;

Private Sub Form_BeforeUpdate (Cancel As Integer)

If Not IsNull(Me![ExitDate]) Then
If Nz(Me![ExitReason], "") = "" Then
MsgBox "You must enter an exit reason"
Cancel = True
Me![ExitReason].SetFocus
End If
End If

End Sub
 
J

John W. Vinson

I have two fields one call exit date and the other one exit reason. If a date
is enter in the exit date field i want the exit reason to be a require field.
How can i do that

If the date is Null, the reason can be null also?

If so, open the form in design view; view its properties; find the
BeforeUpdate event on the Events tab. Click the ... icon by it and choose
"Code Builder". Edit it to something like the following (use your own textbox
names of course):

Private Sub Form_BeforeUpdate(Cancel as Integer)
If Not IsNull(Me!txtExitDate) Then
If IsNull(Me!txtExitReason) Then
Cancel = True
MsgBox "Please enter an exit reason", vbOKOnly
Me!txtExitReason.SetFocus
End If
End If
End Sub
 
J

Jessica

I enter the code below, it does ask me to enter an exit reason. But after i
get that message i also get an error message: stating the Object doesn't
suppor this property or method run time error 438. Do i suppose to get that
message.

Beetle said:
In the forms Before Update event;

Private Sub Form_BeforeUpdate (Cancel As Integer)

If Not IsNull(Me![ExitDate]) Then
If Nz(Me![ExitReason], "") = "" Then
MsgBox "You must enter an exit reason"
Cancel = True
Me![ExitReason].SetFocus
End If
End If

End Sub

--
_________

Sean Bailey


Jessica said:
I have two fields one call exit date and the other one exit reason. If a date
is enter in the exit date field i want the exit reason to be a require field.
How can i do that
 
J

Jessica

when i click debug it Highlights the Me![Exit Reason].setfocus part.

Beetle said:
In the forms Before Update event;

Private Sub Form_BeforeUpdate (Cancel As Integer)

If Not IsNull(Me![ExitDate]) Then
If Nz(Me![ExitReason], "") = "" Then
MsgBox "You must enter an exit reason"
Cancel = True
Me![ExitReason].SetFocus
End If
End If

End Sub

--
_________

Sean Bailey


Jessica said:
I have two fields one call exit date and the other one exit reason. If a date
is enter in the exit date field i want the exit reason to be a require field.
How can i do that
 
J

John W. Vinson

when i click debug it Highlights the Me![Exit Reason].setfocus part.

If your textbox is named txtExitReason use it instead. You can set the focus
to a textbox, but not to a table field:

Me![txtExitReason].SetFocus
 
J

Jessica

Is not working i get the message Run Time Error 438 Object Doesn't Suppor
this property or method Me![Closing Reason].SetFocus

Beetle said:
In the forms Before Update event;

Private Sub Form_BeforeUpdate (Cancel As Integer)

If Not IsNull(Me![ExitDate]) Then
If Nz(Me![ExitReason], "") = "" Then
MsgBox "You must enter an exit reason"
Cancel = True
Me![ExitReason].SetFocus
End If
End If

End Sub

--
_________

Sean Bailey


Jessica said:
I have two fields one call exit date and the other one exit reason. If a date
is enter in the exit date field i want the exit reason to be a require field.
How can i do that
 
J

John W. Vinson

Is not working i get the message Run Time Error 438 Object Doesn't Suppor
this property or method Me![Closing Reason].SetFocus

What is [Closing Reason]?

Is it the name of a field in your table? You can't set focus to a field in a
table, only to a Control on a Form.

What is the Name property of the textbox on the form which is bound to the
Closing Reason field?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top