UNDO for unbound control, NOTHING WORKS

M

Marshall Barton

rgrantz said:
I have an unbound form in which users input the Start Date and End Date to
use for reports that open based on the button clicked. When the user enters
a date syntax wrong (ie. 1//2/03), it seems the place to capture the 2113
(invalid entry) error is in the form's OnError event, NOT the control's
BeforeUpdate event. I am able to trap and show my own msgbox, but cannot
for the life of me undo the text entered in the date field. None of the
following works after the dataerr = 2113 check:

cancel = true
me.undo
me.controlname.undo
me.controlname = ""
me.controlname.text = ""
me.controlname.value = ""
me.controlname = null

All the posts I've seen on undoing unbound control entry say to use
me.controlname.undo, but this does nothing. The Esc key works, and I've
seen that me.undo is supposed to duplicate the pressing of the Esc key, but
it isn't.


You can not change the value in the Form's Error event, so
all your Me.Controlname = . . . tries won't work.

I just checked it in AXP and Me.controlname.Undo worked for
me in the form's Error event. You didn't mention it, but I
don't think you'll get an error unless you set the control's
Format property to a date format.
 
R

rgrantz

I have an unbound form in which users input the Start Date and End Date to
use for reports that open based on the button clicked. When the user enters
a date syntax wrong (ie. 1//2/03), it seems the place to capture the 2113
(invalid entry) error is in the form's OnError event, NOT the control's
BeforeUpdate event. I am able to trap and show my own msgbox, but cannot
for the life of me undo the text entered in the date field. None of the
following works after the dataerr = 2113 check:

cancel = true
me.undo
me.controlname.undo
me.controlname = ""
me.controlname.text = ""
me.controlname.value = ""
me.controlname = null

All the posts I've seen on undoing unbound control entry say to use
me.controlname.undo, but this does nothing. The Esc key works, and I've
seen that me.undo is supposed to duplicate the pressing of the Esc key, but
it isn't.

I not only want to undo the entry so the user has to re-enter, but also
because I need them to be able to press my "cancel report and return to main
menu" button. They can't leave the form if they entered an invalid date
syntax until they use the Esc key to undo their entry.

I apologize for the extreme newbieness of this post, but I'm at my wit's end
here.

Any help is greatly appreciated, and thanks.
 
R

rgrantz

In classic "me tearing my hair out for an hour and then finally posting and
then trying other stuff while I wait" style, I hit upon something that
worked:

For anyone else running into this problem, the following in the form's On
Error event worked:

Private Sub Form_Error(DataErr As Integer, Response As Integer)
Select Case DataErr
Case 2113
MsgBox "Date must be in mm/dd/yy format", vbOKOnly, "Wrong Date
Syntax"
Response = acDataErrContinue
Me.ActiveControl.Undo
Case Else
MsgBox Err.Number & " - " & Err.Description
End Select
End Sub

It seems that for some reason me.activecontrol works when
me.ActualControlName doesn't. I STILL think that's weird.
 
P

PC Datasheet

If it is an unbound form, there is no record to save the Start Date and End
Date. So put code in the End date Enter event to check that Start Date is
not null and if it is set the focus back to Start Date. This will force the
user to enter a Strat Date before the End Date. Then put code in the End
Date's After Update event to first check that End Date is the same as or
after Start Date. If it is not, raise a message and then set Strat Date to
Null. If it is run your report.

In your error handler, you can set End Date or both dates to Null.
 

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