Required entries

E

Ernie Sersen

I have a 'LOG IN' or 'LOG OUT' button on a form that a user depresses when
logging a part into or out of inventory. I also have two field, WHSE and
STATUS, that must be populated BEFORE the user can LOG the part in or out
using the buttons. If either (or both) of these fields are empty and the
user hits the LOG IN or LOG OUT button, can a prompt be displayed 'WHSE is
Required' or 'STATUS is Required'? Also, if the user tries to leave the
subform before hitting the LOG IN or LOG OUT buttons, can he/she be prompted
"MUST LOG IN/OUT before leaving subform"? I assume the first event is
coded in the buttons' 'On Click' event and the second is coded in the subform
'Lost Focus' event. Any help would be appreciated. THANKS.
 
M

mscertified

Your idea will work but is not the best solution. You should make the buttons
not enabled until the required information has been entered and then enable
the button.

In your OPEN event for subform, put:
Me!LogInButton.enabled = False
Me!LogOutButton.enabled = False

In your afterupdate event for the WHSE and STATUS, put:
If isnull(Me!WHSE) or isnull(Me!STATUS) Then
Me!LogInButton.enabled = False
Me!LogOutButton.enabled = False
Else
Me!LogInButton.enabled = True
Me!LogOutButton.enabled = True
End if

This code is just off the top of my head so may need tinkering with but hope
you get the idea.

Dorian
 
E

Ernie Sersen

Thanks, Dorian. I'll give this a try. Will this also solve the problem of
my users leaving the subform before hitting either of the LOG buttons?
 
M

Marshall Barton

Ernie said:
I have a 'LOG IN' or 'LOG OUT' button on a form that a user depresses when
logging a part into or out of inventory. I also have two field, WHSE and
STATUS, that must be populated BEFORE the user can LOG the part in or out
using the buttons. If either (or both) of these fields are empty and the
user hits the LOG IN or LOG OUT button, can a prompt be displayed 'WHSE is
Required' or 'STATUS is Required'? Also, if the user tries to leave the
subform before hitting the LOG IN or LOG OUT buttons, can he/she be prompted
"MUST LOG IN/OUT before leaving subform"? I assume the first event is
coded in the buttons' 'On Click' event and the second is coded in the subform
'Lost Focus' event.


You need a place to keep track of the buttons that have been
clicked. I suggest that you use an invisible text box named
txtClicks in the form's header section.

Both button's click events could be:

If IsNull(Me.WHSE) Then
MsgBox "WHSE is Required"
Me.WHSE.Setfocus
Exit Sub
End If
If IsNull(Me.WHSE) Or IsNull(Me.STATUS) Then
MsgBox "STATUS is Required"
Me.STATUS.Setfocus
Exit Sub
End If
Me.txtClicks = "Logged"

On the main form's subform control's Exit event:

With Me.subformcontrol
If .Form.txtClicks <> "Logged" Then
MsgBox "log something first"
Cancel = True
Else
.Form.txtClicks = Null
End If
End With
 
M

mscertified

No, my solution did not address that issue. For that you will have to display
a message. I cant remember if the lost focus event is cancellable; you really
need to put that code in an event that is cancellable so your user is forced
back to the subform. Presumably you only want to do this if the user has
entered some data.

Dorian
 
Top