Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Forms Programming / May 2007

Tip: Looking for answers? Try searching our database.

How to Write Code?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
hdfixitup - 31 May 2007 04:50 GMT
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.
Scott McDaniel - 31 May 2007 11:20 GMT
>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
hdfixitup - 31 May 2007 14:39 GMT
MY BAD!  I did a poor job of explaining what I want to do.  I currently have
code running the queries and moving the control to a specific field.  
Currently, when I get to my control, I click the mouse and another set of
code is run (like stopping the code and waiting for user input). I want to
automate this process.  I want to get to my field AND then have the "On
Click" event begin to execute the remaining code.  I don't know how to write
DoCmd. Run Ommand "On Click" to complete the task at hand. I hope I am a
little clearer this time.

> >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
[quoted text clipped - 38 lines]
> scott@takemeout_infotrakker.com
> www.infotrakker.com
missinglinq - 31 May 2007 14:59 GMT
You just invoke the Click sub for your command button:

Private Sub YourCommandButton_GotFocus()
  YourCommandButton_Click
End Sub

But you really need to pay attention to Scott's warning! Any code you have in

Private Sub YourCommandButton_GotFocus()

will not only be carried out when your queries have run and your code directs
the foucs to your command button, it'll be carried out anytime the user tabs
onto the command button; do you really want that?

Signature

There's ALWAYS more than one way to skin a cat!

Answers/posts based on Access 2000

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.