First VBA for query

gumbi17

Registered User.
Local time
Today, 06:42
Joined
Aug 23, 2011
Messages
43
I have a form that I need it to run a query when the form is being close, but I am running into a tad bit of trouble. First off this is my first VBA code so please bare with me! Here is what I have so far:

Public Sub Form_Close()
With DoCmd
.SetWarnings False
.OpenQuery(FixLeaseNum,acViewNormal,acAdd)
.SetWarnings True
End With
End Sub

The problem is that when I try the query it works at updating another table, but when I run it as the form is closing the form it does not update the other table. The query is an update query to bring information from another table into the main table of the form the user is using! Help!!!
 
Try this"

Public Sub Form_Close()
DoCmd.SetWarnings False
Docmd.OpenQuery "FixLeaseNum"
Docmd.SetWarnings True

End Sub
 
Thanks! I guess the docmd in front works better than the with DOCmd line header. Good to know, and also with the quotes, is there a reason when you are writing the code, underneath it is showing you that you need the ()?
 
Not sure about the () but I know it works with " ". GLad to help.
 

Users who are viewing this thread

Back
Top Bottom