Quote:
Originally Posted by Trebormac
I have a make table query that I would like to run from VBA. I want to be able to add or change the table name. What would be the sytax to do this via VBA?
Thanks,
Trebormac
|
This is almost a month old, but here goes:
1. Create your make table query in the QBE grid and then
2. take the SQL of that to the VBA Window
3. You can then modify the SQL code
for example if you have a query like this:
SELECT sbqryAdmitDeals.lt_name, sbqryAdmitDeals.PortfolioName, sbqryAdmitDeals.FullName, sbqryAdmitDeals.RoleLeadFK, sbqryTRFS.RepTypeName, sbqryTRFS.RepRecd, sbqryTRFS.Status, CDate(Format(Now(),"Short Date"))-[RepRecd] AS Days, 2 AS OrderID
INTO mtblFSRcvd
FROM sbqryAdmitDeals INNER JOIN sbqryTRFS ON sbqryAdmitDeals.PropertyFK = sbqryTRFS.PropertyFK
WHERE (((sbqryAdmitDeals.RoleLeadFK)=[Forms]![frmReports]![cboPrimaryContact]) AND ((sbqryTRFS.RepTypeFK)=6));
You can use this SQL in code
Code:
Dim strSQL As String
strSQL = "SELECT sbqryAdmitDeals.lt_name, sbqryAdmitDeals.PortfolioName, " & _
"sbqryAdmitDeals.FullName, sbqryAdmitDeals.RoleLeadFK, sbqryTRFS.RepTypeName, " & _
"sbqryTRFS.RepRecd, sbqryTRFS.Status, CDate(Format(Now(),"Short Date"))-[RepRecd] AS Days, 2 AS OrderID " & _
"INTO " & YourVariableNameHere & _
"FROM sbqryAdmitDeals " & _
"INNER JOIN sbqryTRFS ON sbqryAdmitDeals.PropertyFK = sbqryTRFS.PropertyFK " & _
"WHERE (((sbqryAdmitDeals.RoleLeadFK)= " & [Forms]![frmReports]![cboPrimaryContact] & _
") AND ((sbqryTRFS.RepTypeFK)=6));"