I have a command button that runs a series of queries and moves to a control
on the form. I want to run the Event Procedure "On Click" when the control
gets focus. How do I write the code using the DoCmd. >>>>> to trigger this
event? Any help would be appreciated.
You can run a query like this:
Currentdb.Execute "NameOfYourQuery"
or
DoCmd.OPenQuery "NameOfYourQuery"
to move to a control, use SetFocus: Me.YourControl.SetFocus
If you need to call the code in multiple places, you would be better off moving that code to a function or sub call,
then calling that function/sub as needed. For eg:
Sub RunQueries()
Currentdb.Execute "Query1"
Currentdb.Execute "Query2"
Currentdb.Exectue "Query3"
End Sub
Now call this as needed
Sub MyButton_Click()
RunQueries
Me.SomeControl.SetFocus
End Sub
Sub MyTextbox_GotFocus()
RunQueries
End Sub
Althoug I'd advise that you think long and hard about using GotFocus to run queries ... anytime you're manipulating
data, you're better off letting the user start the process. This isn't a hard and fast rule, mind you, just be careful
when doing something like this.
Scott McDaniel
scott@takemeout_infotrakker.com
www.infotrakker.com