> Unfortunately the the DAO samples I found in the myodbc-FAQ do not work.
> Neitehr from within Access nor from plain VB.
> The ADO samples work though.
This is from actual, working code - VB 6.0:
Dim MyDB As Database, MyRS As Recordset
' grab NameStr, ConnectStr from registry
NameStr = GetSetting(App.EXEName, "CONNECTION", "NSTR")
ConnectStr = GetSetting(App.EXEName, "CONNECTION", "CSTR")
If ConnectStr = "" Then ConnectStr = "ODBC;"
Debug.Print NameStr
Debug.Print ConnectStr
MyDBName = "LocalDB.MDB"
' what this code does is connect via ODBC - if that fails, connect to the
local database
On Error Resume Next
Err = 1
While Err <> 0
Err = 0
If ConnectStr <> "" Then
Set MyDB = OpenDatabase(NameStr, dbDriverNoPrompt, False,
ConnectStr)
Else
Set MyDB = OpenDatabase(NameStr)
End If
Debug.Print Err; ": "; Error$
If Err = 3059 Then
NameStr = MyDBName
ConnectStr = ""
Else
If Err = 3024 Then
End
Else
NameStr = MyDB.Name
ConnectStr = MyDB.Connect
End If
End If
If Err <> 0 Then Pause 5
Wend
On Error GoTo 0
If ConnectStr <> "" Then
SaveSetting App.EXEName, "CONNECTION", "CSTR", ConnectStr
SaveSetting App.EXEName, "CONNECTION", "NSTR", NameStr
End If
' at this point, we can do queries, etc. Don't forget to add
dbSQLPassThrough, or your SQL will run dog-slow!