Hi Guys,
I am trying to run pass through code below:
Code:
Public Sub InitConnect()
On Error GoTo ErrHandler
Dim dbCurrent As DAO.Database
Dim qdf As DAO.QueryDef
Dim rst As DAO.Recordset
Dim cnn As Object
Set cnn = CreateObject("ADODB.Connection")
sConnString = "DRIVER={PostgreSQL Unicode};DATABASE=AccessLog;SERVER=localhost;PORT=5432;UID=postgres;PWD=1234;"
cnn.Open sConnString
Set dbCurrent = DBEngine(0)(0)
Set qdf = dbCurrent.CreateQueryDef("")
With qdf
.Connect = sConnString
.SQL = "SELECT CURRENT_USER;"
Set rst = .OpenRecordset(dbOpenSnapshot, dbSQLPassThrough)
End With
'' InitConnect = True
ExitProcedure:
On Error Resume Next
Set rst = Nothing
Set qdf = Nothing
Set dbCurrent = Nothing
Exit Sub
ErrHandler:
''InitConnect = False
MsgBox Err.Description & " (" & Err.Number & ") encountered", _
vbOKOnly + vbCritical, "InitConnect"
Resume ExitProcedure
Resume
End Sub
And i have error with " .SQL = "SELECT CURRENT_USER;"
When i am creating query like here manually:
This is working like a charm.
I am working on windows 10, 64 bit system.
Access is:
And postgresql is PostgreSQL 10.4, compiled by Visual C++ build 1800, 64-bit.
When i am creating ODBC in 64 bit settings :
it doesn't work.
Only Odbc 32 bit settings works in Access while linking tables (i think that this is caused by having Access 32 bit)
And other strange thing, changing line of code to :
Code:
sConnString = CurrentDb.TableDefs("t_versions").Connect
The string is the same like in this manually set up pass through query.
causes error like here:
https://stackoverflow.com/questions/...-default-drive
Why this is not working?
Please help,
Jacek Antek