D
Dave
I am trying to connect to an ODBC data source using VBA and I am
running into problems. The main problem occurs when my code queries a
table that isn't in the database. I'd like to just receive an error
and then respond to the error, but that isn't happening. As soon as the
query is attempted, it brings the computer to a complete halt with no
error codes. I am thinking that I need to get into using ODBC function
calls to interact with the database, but I am inexperienced using API
functions. I was just wondering if anyone could post some example code
using ODBC function calls.
Thanks.
FWIW, I am connecting like this:
----------------------------------------------------
Set wrkDBE = DBEngine.CreateWorkspace("tempWS", "admin", vbNullString)
Set condbs = wrkDBE.OpenDatabase("", 0, 0, "ODBC;DSN=insite;")
If Err.Number = 3151 Then Exit Sub
For Each tblObj In condbs.TableDefs
If Err.Number = 3146 Then Exit Sub
If tblObj.Name Like "* Info<Bag>" Then
Blah Blah Blah
condbs.Close
wrkDBE.Close
And like this:
---------------------------------------
Set wrkODBC = CreateWorkspace("ODBCWorkspace", "", "", dbUseODBC)
Set condbs = wrkODBC.OpenDatabase("ODBC;DSN=insite;")
Set rst(0) = condbs.OpenRecordset("SELECT * FROM ADI.""" & WellName
& _
SqlSep & WellBased & SqlSep & "Well Info<Bag>""")
condbs.Close
wrkODBC.Close
running into problems. The main problem occurs when my code queries a
table that isn't in the database. I'd like to just receive an error
and then respond to the error, but that isn't happening. As soon as the
query is attempted, it brings the computer to a complete halt with no
error codes. I am thinking that I need to get into using ODBC function
calls to interact with the database, but I am inexperienced using API
functions. I was just wondering if anyone could post some example code
using ODBC function calls.
Thanks.
FWIW, I am connecting like this:
----------------------------------------------------
Set wrkDBE = DBEngine.CreateWorkspace("tempWS", "admin", vbNullString)
Set condbs = wrkDBE.OpenDatabase("", 0, 0, "ODBC;DSN=insite;")
If Err.Number = 3151 Then Exit Sub
For Each tblObj In condbs.TableDefs
If Err.Number = 3146 Then Exit Sub
If tblObj.Name Like "* Info<Bag>" Then
Blah Blah Blah
condbs.Close
wrkDBE.Close
And like this:
---------------------------------------
Set wrkODBC = CreateWorkspace("ODBCWorkspace", "", "", dbUseODBC)
Set condbs = wrkODBC.OpenDatabase("ODBC;DSN=insite;")
Set rst(0) = condbs.OpenRecordset("SELECT * FROM ADI.""" & WellName
& _
SqlSep & WellBased & SqlSep & "Well Info<Bag>""")
condbs.Close
wrkODBC.Close