How to change destination table in VBA

  • Thread starter Thread starter Dan
  • Start date Start date
D

Dan

Hi,


I am try to change the destination table name from an
append query. Is there anyway I can say in VBA that
DestinationTable = [NewTableName], instead of writing SQL
statment of creating a table in the VBA?
Since I did the query in access, I just want to be
changing the destination table name in VBA. The name
will always have the date added to it so that is why I
need to change the name in the append query.

Thank you
 
Open the QueryDef object, and look at its SQL property.

Assuming you have a reference set to DAO 3.x, it'll be something like:

Dim dbCurr As Database
Dim qdfCurr As QueryDef
Dim strSQL As String

Set dbCurr = CurrentDb()
Set qdfCurr = dbCurr.QueryDefs("MyQueryName")
strSQL = qdfCurr.SQL

' Write code to modify the file name in the SQL string

qdfCurr.SQL = strSQL

Set dbCurr = Nothing
 
Back
Top