How can I get a Make Table query to run via VBA/ADO/Macro? (1 Viewer)

boulderman

New member
Local time
Today, 05:26
Joined
Aug 22, 2011
Messages
2
The closest Argument I can find is OpenQuery which merely opens it.

How do I get a Make Table Query to run, either using VBA, ADO or Macro.

The following is the SQL for one of the Make Tables:

PHP:
SELECT Details.Field33, Details.Field14, Details.Field15, Details.Field2, Details.Field16, Count(Details.Field26) AS CountOfField26, Count(Details.Field23) AS CountOfField23, Details.Field30, Sum(Round([Field29],2)) AS Expr3, Round(Sum((IIf([Details.field34]>'0',[Details.Field29]-[Details.Field34],0))),2) AS Expr1, Details.Field12, Left(Replace([Field4]," ",""),7) AS Expr2, Details.Field1 INTO [EPLOGP Data C]
FROM Details
GROUP BY Details.Field33, Details.Field14, Details.Field15, Details.Field2, Details.Field16, Details.Field30, Details.Field12, Left(Replace([Field4]," ",""),7), Details.Field1, Details.Field6
HAVING (((Count(Details.Field26)) Is Not Null) AND ((Count(Details.Field23)) Is Not Null) AND ((Details.Field6) Not In ('','0','00','12','38','41','43','42')));

Thanks
 

mdlueck

Sr. Application Developer
Local time
Today, 00:26
Joined
Jun 23, 2011
Messages
2,631
This will at least populate a table in the FE database:

Code:
Public Function RefreshLocalTmpTbl()
On Error GoTo Err_RefreshLocalTmpTbl

  Dim adoCMD As ADODB.Command
  Dim strSQL As String

  'Define attachment to database table specifics
  Set adoCMD = New ADODB.Command
  adoCMD.ActiveConnection = CurrentProject.Connection

  'Define a query to refresh the temp table with records part of the OrderNumber
  strSQL = "INSERT INTO tmptblqry_projects (id, authid, logtimestamp, title) " & _
            "SELECT dbo_projects.id, dbo_projects.authid, dbo_projects.logtimestamp, dbo_projects.title " & _
            "FROM dbo_projects;"

  'Pass the SQL to the Command object
  adoCMD.CommandText = strSQL

  'Execute the SQL
  adoCMD.Execute
  
  'Good return code
  RefreshLocalTmpTbl = 0

Exit_RefreshLocalTmpTbl:
  'Clean up the connection to the database
  Set adoCMD = Nothing

  Exit Function

Err_RefreshLocalTmpTbl:
  Call errorhandler_MsgBox("Class: clsObjProjectsTbl, Function: RefreshLocalTmpTbl()")
  RefreshLocalTmpTbl = -1
  Resume Exit_RefreshLocalTmpTbl

End Function
I leave all of the FE tables created in the FE database, "DELETE *" to purge old data, and always copy down a clean copy of the FE DB when the application starts up.

Thus I do not have example code of DDL within VBA.
 

Mr. B

"Doctor Access"
Local time
Yesterday, 23:26
Joined
May 20, 2009
Messages
1,932
If you have named action query defined (Make Table, Delete, Update, etc.) and want to run that query using VBA you would use the following statement in the desired event or module:

Code:
CurrentDb.Execute "TheNameOfYourQuery"

Just replase the "TheNameOfYourQuery" with the actual name of the query you want to run.
 

Users who are viewing this thread

Top Bottom