Hi folks,
How do you create a query that will run on a temporary table?
And then how do you ask through vba to run the query?
If you look at my code below:
I am essentially temporary linking a file, & I want to extract certain fields from that table.
But before I extract, I need to delete and unneccessary information & repeat some data in order to have no blank fields.
Later, I'll be cleaning the repeated information.
Code:
Function LinkExternal(ByVal conString As String, sourceTable As String)
Dim db As Database
Dim i As Integer
Dim j As Integer
Dim linktbldef As TableDef
Dim rst As Recordset
Set db = CurrentDb
Set linktbldef = db.CreateTableDef("tmptable") 'create temporary table definition
linktbldef.Connect = conString 'set the connection string
' run query: delete all blank records in tmptable
' run query: delete all unimportant fields
' run query: append/repeat clientname for their respective order
' run query: add field companyname, get data from form
linktbldef.SourceTableName = sourceTable 'attach the source table
db.TableDefs.Append linktbldef 'add the table definition to the group
db.TableDefs.Refresh 'refresh the tabledefinitions
linktbldef.Name = sourceTable 'rename the tmptable to original source table name
db.TableDefs.Delete sourceTable 'remove to keep the table linked
db.Close
Set linktbldef = Nothing
Set db = Nothing
End Function