Unbound control, abandon entry

R

redFred

Be kind: I am self-taught, merely an amateur at this.

I have a control (unbound) wherein the user enters a date. This date is
then used elsewhere (bound controls), destination per criteria.

User enters a date, or partial date and wishes to close the form, NOT
hitting the Enter key but leaving "trash" in suspense.

How can I test this unbound control for "trash" when the user clicks the
Close button, without ever having hit the enter key while focus is in the
unbound control, which would make a valid entry? Leaving "trash" and closing
the form actually updates elsewhere as if the user accepted the date.

The close button is clicked as follows:
1. Routinely: a date entered into this unbound control and work is done
with date.
2. User may open the form, and immediately close it.
3. User may partial enter date and change mind, with "trash" in unbound
control.

It may be a case of cerebral flatulence, but I would appreciate some advice.

Thanks,
 
J

John W. Vinson

Be kind: I am self-taught, merely an amateur at this.

I have a control (unbound) wherein the user enters a date. This date is
then used elsewhere (bound controls), destination per criteria.

User enters a date, or partial date and wishes to close the form, NOT
hitting the Enter key but leaving "trash" in suspense.

How can I test this unbound control for "trash" when the user clicks the
Close button, without ever having hit the enter key while focus is in the
unbound control, which would make a valid entry? Leaving "trash" and closing
the form actually updates elsewhere as if the user accepted the date.

The close button is clicked as follows:
1. Routinely: a date entered into this unbound control and work is done
with date.
2. User may open the form, and immediately close it.
3. User may partial enter date and change mind, with "trash" in unbound
control.

It may be a case of cerebral flatulence, but I would appreciate some advice.

Thanks,

Put code in your close button's click event:

If IsDate(Me!controlname) Then
<it's a valid date>
Else
<it's rubbish>
End If

Of course the user could enter something that looks like a valid date but is
(in terms of your business rules) garbage - e.g. if you require years, the
user could enter 11/5 and quit, and Access would interpret it as 11/5/2008.
 
R

redFred

Thanks...but it is still closing and updating.


My code for the button (made from label):
'tests for trash field, warns user to correct
If IsDate(Me!txtLaborPRDate) Then
response = MsgBox(msg, style, title)
Exit Sub
Else
DoCmd.Close
End If

[txtLaborPRDate] is unbound, formatted m/d/yy.

I cannot get anything to test this unbound. What could be my issue? (Other
than lack of experience?)

Thanks,
 
J

John W. Vinson

Thanks...but it is still closing and updating.

Try explicitly clearing the control - or the form itself - if the field is
invalid:

My code for the button (made from label):
'tests for trash field, warns user to correct
If IsDate(Me!txtLaborPRDate) Then
response = MsgBox(msg, style, title)
Exit Sub
Else
Me.txtLaborPrDate = Null

-or-

Me.Undo

DoCmd.Close
End If
 
R

redFred

Not there yet. I did change around the code to clarify, though.

'tests for trash field, warns user to correct
If IsNull(Me.txtLaborPRDate.Value) Then
DoCmd.Close
Else
response = MsgBox(msg, style, title)
Me.txtLaborPRDate = Null
End If

With this code any entry not followed by Enter key will close form updating
record.

When the control has no input, closing works fine.

How do I test the input characters for existence before hitting the Enter
key? Remember this is unbound control so no record is directly updated.

Thanks for your help,
 

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