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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Running Multiple Queries

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Okay, I'm a Newbie and I'm stuck. I have a computer equipment inventory DB with multiple tables. When an older computer is replaced it is moved from a current inventory table to a retired table until it is donated or disposed of. To automate this process I built an append query and a delete query. The Append query copies the selected records from the current table to the retired table and then the delete query deletes the selected records from the current table. If each query is run separately they work fine. I'm trying to run both queries in VBA from a command button, but can't seem to get it to work. I get an error saying "Access cant find the object qryDelete" (the delete query). Any help is greatly appreciated. Here's the code:

Private Sub cmdRetire_Click()
On Error GoTo Err_cmdRetire_Click

Dim stDocName As String
DoCmd.SetWarnings False
stDocName = "qryAppend"
DoCmd.OpenQuery stDocName, acNormal, acEdit
stDocName = "qryDelete"
DoCmd.OpenTable stDocName, acViewNormal, acEdit
DoCmd.SetWarnings True

Exit_cmdRetire_Click:
Exit Sub

Err_cmdRetire_Click:
MsgBox Err.Description
Resume Exit_cmdRetire_Click

End Sub

Thanks, VBA Guy
 
This is the most obvious thing when I look at your code:

stDocName = "qryAppend"
DoCmd.OpenQuery stDocName, acNormal, acEdit
stDocName = "qryDelete"
DoCmd.OpenTable stDocName, acViewNormal, acEdit
Jonathan
________________________________________
It is not fair to ask of others what you are unwilling to do yourself.
-Eleanor Roosevelt
 
Thanks Jonathan,

Someone helped me with the code and you did point out the very obvious. I'm so green that I didn't realize this mistake until you pointed it out. Many Thanks.

VBA Guy
 

We've ALL been there. Don't worry about it.
I wasn't trying to say "This is obvious and you should have seen it" I was saying "I didn't look too long at this, but this is most obvious thing I see" Jonathan
________________________________________
It is not fair to ask of others what you are unwilling to do yourself.
-Eleanor Roosevelt
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top