pass through query not working correctly via VBA in Access
I am trying to set a passthrough query to run via VBA the code grabs the product ID and puts that in the SQL for the passthrough it them is suppose to run a append query that runs off of the pass though to append the records into a table in access. If I set this up in access it runs fine, but when I try to run it via the VBA code I get an error when I get to the append query "0100 get samples"
The error says Cannot find file c:\Documents and settings\amcfall\My Documents\siebel.mbd.
Something happens to the passthrough when the code exectues, the SQL looks ok but the connection part doesn't, I first have to reset the query type to passthrough and then reset the ODBC connection information in the property sheet, so I assume what is happening is that the code is not correct to set up the passthrough in the VBA...
With rstTest
Do Until rstTest.EOF
sProdId = rstTest!ROW_ID
CurrentDb.QueryDefs.Delete "qry_samples"
Set crsePassThru = CurrentDb.CreateQueryDef("qry_samples")
With crsePassThru
.ReturnsRecords = True
You should build a pass through querydef and just modify the .sql property, save and execute. While you're at it you can build the connect string also.
This covers the connect string, getting user name and populating the .connect property of the querydef.
Jim
'I use constants just to store basic connect string info' if using trusted rather than mixed mode substitute Trusted_Connection=yes for PWD.Public Const strConnect1 = "ODBC;DRIVER={SQL SERVER};SERVER=999.999.999.999\SQLEXPRESS;DATABASE=MySQLDb;UID="Public Const strConnect2 = ";PWD=xxxxx;ADDRESS=999.999.999.999;"'call to api th grab user namePrivate Declare Function GetUserName Lib "ADVAPI32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As LongPublic gUserNm as string'get user name, you'll use it in connect stringPublic Function GetCurrentUserName() As StringOn Error GoTo Err_GetCurrentUserName Dim lpBuff As String * 255 Dim ret As Long, Username As String ret = GetUserName(lpBuff, 255) Username = Left(lpBuff, InStr(lpBuff, Chr(0)) - 1) GetCurrentUserName = Username & "" gUsrNm = GetCurrentUserNameExit_GetCurrentUserName: Exit FunctionErr_GetCurrentUserName: MsgBox Err.Description Resume Exit_GetCurrentUserNameEnd Function'connect string property of pass thru querydef gets updated herePublic Sub SetSQLConnectString()Dim db As DAO.DatabaseSet db = CurrentDbdb.QueryDefs("qptGetUpdateDate").Connect = strConnect1 & gUsrNm & strConnect2End Sub
Squarespace’s all-in-one platform gives you everything you need to express yourself creatively online, whether it is with a domain, website, or online store. Get started with your free trial today, and when ready, take 10% off your first purchase with offer code 'EXPERTS'.
I guess that SIEBEL didn't register with me either... You can modify the Constants for your info, but I think that you're going to have to provide a network library reference in the connect string also. But I really don't know.
You can call the functions, etc in a forms OnLoad event if a form opens when your app does. But since you probably aren't using Windows authentication, the GetUser probably won't help you. The connect string can also be put in the onload event. Does that help?
The Oracle DBAs at my clients won't allow me to connect at all due to some high security data. You will find connect string information at http://www.connectionstrings.com/. I know they have an Oracle section, but since I've never had a need, I've never checked it out.
I wish that I could be of more help on this
Jim
0
Question has a verified solution.
Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.
Ready to showcase your work, publish content or promote your business online? With Squarespace’s award-winning templates and 24/7 customer service, getting started is simple. Head to Squarespace.com and use offer code ‘EXPERTS’ to get 10% off your first purchase.
I'll post some code shortly.
Jim