Hello,
I've got a problem that I can't seem to figure out. Here's some back story on the system I work with. In the company I work for I have 32 separate sales divisions. I need to pull each division's customers on a weekly basis and put them into their own tables. Now the database that holds the customer information is on SQL Server, and I've been told that anytime I hit the SQL server I need to use pass-through queries (which isn't a problem).
I also use this database for other reporting jobs that I do, which come from the same SQL server and I'm trying to keep bloat to a minimum so I do as much as possible with code, and I try to not have static files laying around either (tables or queries).
Now that you've got some back story, here's my real issue.
basically I get the vendor codes for all the divisions in the recordset. then I roll through that recordset making the pass-through queries. and while I'm doing that I'm also trying to create tables from those pass-through queries
the line I'm having problems with is
DoCmd.RunSQL ("Select * Into '" & strParentVendorID & "' From '" & strQueryName & "' ")
It keeps throwing runtime error 3450
any help would be greatly appreciated.
I've got a problem that I can't seem to figure out. Here's some back story on the system I work with. In the company I work for I have 32 separate sales divisions. I need to pull each division's customers on a weekly basis and put them into their own tables. Now the database that holds the customer information is on SQL Server, and I've been told that anytime I hit the SQL server I need to use pass-through queries (which isn't a problem).
I also use this database for other reporting jobs that I do, which come from the same SQL server and I'm trying to keep bloat to a minimum so I do as much as possible with code, and I try to not have static files laying around either (tables or queries).
Now that you've got some back story, here's my real issue.
Code:
Set sqlConn = New ADODB.Connection
sqlConn.ConnectionString = "odbc;DRIVER=SQL Server;Server=*****;Database=*****;Uid=*****;Pwd*****;"
sqlConn.Open strConn, "******", "*******"
Set sqlRecordSet = New ADODB.Recordset
sqlQuery = "SELECT DISTINCT vendor_ref.parent_vendor_id FROM vendor_ref;"
sqlRecordSet.Open sqlQuery, sqlConn, adOpenKeyset, adLockOptimistic
With sqlRecordSet
Do While Not .EOF
strParentVendorID = .Fields(0)
'MsgBox (strParentVendorID) this is only used to verify what sqlparentvendorid contained
Set sqlQueryDef = db.CreateQueryDef(strParentVendorID & "-Pull")
sqlQueryDef.Connect = "odbc;DRIVER=SQL Server;Server=olorin;Database=myinfo;Uid=amuadmin;Pwd=@muDB0wner;"
sqlQueryDef.SQL = "SELECT accounts.first_name, accounts.last_name, accounts.email" & _
" FROM accounts INNER JOIN vendor_ref ON accounts.vendor_id = vendor_ref.vendor_id" & _
" WHERE (((accounts.email) Is Not Null And (accounts.email) Not Like '% %' And (accounts.email) Not Like '%@'" & _
" And (accounts.email) Not Like '@%' And (accounts.email) Not Like '%.GOV' And (accounts.email) Not Like '%.US'" & _
" And (accounts.email) Not Like '%INFOUSA%') AND ((accounts.created_date)<=GetDate()-30) " & _
" AND ((vendor_ref.parent_vendor_id)='" & strParentVendorID & "')) " & _
" GROUP BY accounts.first_name, accounts.last_name, accounts.email;"
sqlQueryDef.Close
strQueryName = strParentVendorID & "-Pull"
strCreateTable = "Select * insert into & strParentVendorID & from & strQueryName &"
DoCmd.RunSQL ("Select * Into '" & strParentVendorID & "' From '" & strQueryName & "' ")
.MoveNext
Loop
End With
basically I get the vendor codes for all the divisions in the recordset. then I roll through that recordset making the pass-through queries. and while I'm doing that I'm also trying to create tables from those pass-through queries
the line I'm having problems with is
DoCmd.RunSQL ("Select * Into '" & strParentVendorID & "' From '" & strQueryName & "' ")
It keeps throwing runtime error 3450
any help would be greatly appreciated.