required fields (1 Viewer)

jojostar

New member
Local time
Yesterday, 20:21
Joined
Oct 28, 2002
Messages
9
I would like to make a field required if data is entered in another field. For example, if field "Date Kit Sent" has a date in it, then "Decision Date" must be filled in before user can save and move on to next record. How do I do that? I am not a programmer but a novice user.
Thanks
 

llkhoutx

Registered User.
Local time
Yesterday, 20:21
Joined
Feb 26, 2001
Messages
4,018
on event field1 after update

if field1 & "" <> "" then ' test for non-blank field
field2.setfocus ' move focus to field 2
end if


then on event field2 Exit

if field2 & "" = "" then
fields1.setfocus 'temporarily to to another field
field2.setfoucs 'moveback to field2 until it get data
end if
 

jojostar

New member
Local time
Yesterday, 20:21
Joined
Oct 28, 2002
Messages
9
Where do I inser that code. Sorry, but I am really green at this. I created a database and now the users are asking for more which is above and beyond me!
:)
 

llkhoutx

Registered User.
Local time
Yesterday, 20:21
Joined
Feb 26, 2001
Messages
4,018
I gave you the events in my response.

Go to the properties for the appropriate controls and click the right margin of the property to build an event.
 

Pat Hartman

Super Moderator
Staff member
Local time
Yesterday, 21:21
Joined
Feb 19, 2002
Messages
43,346
A better place to place code that involves relationships between fields is the BeforeUpdate event of the form. Unless you intend to make a wizard-like process where the user can only move from field-to-field under your program control, you can't really use the Exit or AfterUpdate events of controls to trigger your editing. If the cursor is never placed in a control, its Exit event will never fire. when you place edit code in the BeforeUpdate event of the form, be sure to cancel the update event if any errors are found.

If Len(Me.SomeField) > 0 Then
If Len(Me.SomeOtherField) = 0 Then
MsgBox, "SomeOtherField may not be empty.", vbOKOnly
Me.SomeOtherField.SetFocus
Cancel = True
End If
End If
 

Users who are viewing this thread

Top Bottom