How do you add a field to an existing query using vba?

chillwa

New member
Local time
Today, 14:01
Joined
Jun 16, 2008
Messages
7
How do you add a field to an existing query using vba? Using MS Access module


I need to add/append a table field to an existing select query and save the query using vba code.

1. I will specify the name of the field to be added
2. I need to specify the table it is added from
3. I need to specify in the totals row that it is "SUM"
4. I also need to specify the caption for the newly added field

Then I will save the query


This query is tricky because I am using the "SUM" totals for most of my existing query fields except for 2.


I have been trying to figure this out for a day and a half and I am getting nowhere, ANY help would be appreciated.

I cannot even figure out the code to alter the query.
 
Check out the QueryDef in the Help.

Quickly:

Dim qry as DAO.QueryDef

set qry = Currentdb.QueryDef("MyQuery")

Debug.Print qry.SQL ' shows the SQL from MyQuery

qry.SQL = "SELECT * FROM AnotherTable"

'MyQuery is now changed

qry.close
 
Thanks, it worked. I really appreciate the help
 

Users who are viewing this thread

Back
Top Bottom