Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Automaticly Execute a Query When a Form is Opened

Status
Not open for further replies.

ibwebn65

Programmer
Sep 4, 2002
22
US
I have a query (qryMoveData). This query copies data from fields in the last entry of one table (tblOne) and inserts the data into another table (tblTwo). Since it is copying the data from the last entry in tblOne, no input data is required from a user to select a row. This query has been tested and does everything I want it to do.

I am trying to automaticly execute this query when a form (frmExecute) is opened. I do not want the user to have to click a button to execute the query. I have tried several different coding options, but nothing seems to work. Does anyone have any suggestions?

I'm not the best with VB code, so if you can provide an example code, it would be greatly appreciated. Thank you.
 
Hi...

Have you tried the DoCmd.OpenQuery in the form load event ?
 
Hi

If you go to the properties of your Form and then go to the 'Event' tab you will see an option for 'On Open', select [Event Procedure] and then click the ...

Now type the following code in the VB window:

Private Sub Form_Open(Cancel As Integer)

stDocName = "Query1"
DoCmd.OpenQuery stDocName, acNormal, acEdit

End Sub

Hope this helps
Chris



 
Lewds,

I tried entering the code:

Private Sub Form_Load()
DoCmd.OpenQuery ("qryMoveData")
End Sub

This would be great, but when I execute the form, I get two pop-up windows. Do you know if I can get rid of the pop-up windows?

Pop-up window one says:
"You are about to run an append query that will modify data in your table."

Pop-up window two says:
"You are about to append 1 row(s)."

 
This is part of the main program. Go to the Tools menu in Access and then to Options, then to the Edit/Find tab and remove the ticks under the Confirm section.

Chris
Ps. You may want to leave Confirm Record Deletions ticked!
 
Or play with the DoCmd.SetWarnings method.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
ChrisPanet and PHV,

ChrisPanet, you suggestion looks like it would work, but the database I'm working in has a lot of forms that I did not create. Someone else may want the pop-ups on their form. So, even though your suggestion looks like it will work, I'm trying PHV's suggestion.

PHV, your suggestion about the DoCmd.SetWarnings is working.

The final code looks like this:
'====================
Private Sub Form_Load()
DoCmd.SetWarnings (False) 'Turns OFF pop-up warning messages.
DoCmd.OpenQuery ("qryMoveData") 'Executes query.
DoCmd.SetWarnings (True) 'Turns ON pop-up warning messages.
End Sub
'====================

Thank you to everyone who helped solve this problem!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top