marku24
asked on
Trigger ESC key in VBA code
I am running VBA code to insert data to a table. At the end of the insert I need to manually click the ESC key to reset the form data. Can I trigger this key in code?
Thanks
Thanks
You can do that with SendKeys, but its always best to stay away from SendKey's if possible.
SendKey's goes to the current window, which if your user happens to click else where, may end up getting sent to another window.
Instead, if your trying to undo a form, use the undo method:
Me.Undo
In general, you will find that there are very few things you really need send keys for within Access.
Almost every operation is a method of an existing object.
Jim.
SendKey's goes to the current window, which if your user happens to click else where, may end up getting sent to another window.
Instead, if your trying to undo a form, use the undo method:
Me.Undo
In general, you will find that there are very few things you really need send keys for within Access.
Almost every operation is a method of an existing object.
Jim.
ASKER
i get invalid use of the "Me" function
<No points wanted>
Then try something like this:
Forms!YourFormName.Undo
Then try something like this:
Forms!YourFormName.Undo
You only can use "Me" if the code is in the forms module. If your doing this in a standard module, you'll need to pass in a form reference or a form name as a string so you can reference it and call the undo method.
For example:
Call MyRoutine([Form]) or Call MyRoutine([Me])
Sub MyRoutine(frm as Form)
' Do your process
' Reset form
frm.Undo
End Sub
or with the form name as a string:
Call MyRoutine(Me.Name) or Call MyRoutine("MyFormNameIsThi s")
Sub MyRoutine(strFormName as string)
' Do your process
' Reset form
Forms(strFormName).Undo
End Sub
On the last, if your going to do multiple things with form, your better off to set an object reference:
Sub MyRoutine(strFormName as string)
Dim frm As Form
Set frm = Forms(strFormName)
' Do your process
' Do something to the form
frm.Visible = False
' Reset the form
frm.Undo
' Make it visible and repaint
frm.Visible = True
frm.Repaint
End Sub
Jim.
For example:
Call MyRoutine([Form]) or Call MyRoutine([Me])
Sub MyRoutine(frm as Form)
' Do your process
' Reset form
frm.Undo
End Sub
or with the form name as a string:
Call MyRoutine(Me.Name) or Call MyRoutine("MyFormNameIsThi
Sub MyRoutine(strFormName as string)
' Do your process
' Reset form
Forms(strFormName).Undo
End Sub
On the last, if your going to do multiple things with form, your better off to set an object reference:
Sub MyRoutine(strFormName as string)
Dim frm As Form
Set frm = Forms(strFormName)
' Do your process
' Do something to the form
frm.Visible = False
' Reset the form
frm.Undo
' Make it visible and repaint
frm.Visible = True
frm.Repaint
End Sub
Jim.
ASKER
i think I may get it to work by going to a new record. The reason the ESC works is it resets my Autonumber. A new record would do the same. Can I add a new record somehow by :
myform goto newrecord?
something like that? This may be easier.
myform goto newrecord?
something like that? This may be easier.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
simple but worked perfectly
Open in new window