Hi all
I keep getting a 424 object error in the code and I can't find where the issue is.
Basically what the code does is, when a person gets to the login form, he puts his details in and when he clicks on login, this code will execute to save the connection string temporarily and then discard when the database closes.
Public Function InitConnect(Optional UserName As String, Optional Password As String) As Boolean
On Error GoTo ErrHandler
Dim dbCurrent As dao.Database
Dim qdf As dao.QueryDef
Dim rst As dao.Recordset
strConnection = "ODBC;DRIVER={MySQL ODBC 5.3 Unicode Driver};" & _
"Server=" & SERVER & ";" & _
"Port=" & 3306 & ";" & _
"Option=" & 0 & ";" & _
"Database=" & DATABASENAME & ";"
Set dbCurrent = DBEngine(0)(0)
Set qdf = dbCurrent.CreateQueryDef("")
With qdf
.Connect = strConnection & _
"Uid=" & USERNAME & ";" & _
"Pwd=" & PWD
.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 Function
ErrHandler:
InitConnect = False
MsgBox Err.Description & " (" & Err.Number & ") encountered", _
vbOKOnly + vbCritical, "InitConnect"
Resume ExitProcedure
Resume
End Function
Appreciated.
Jeff
I keep getting a 424 object error in the code and I can't find where the issue is.
Basically what the code does is, when a person gets to the login form, he puts his details in and when he clicks on login, this code will execute to save the connection string temporarily and then discard when the database closes.
Public Function InitConnect(Optional UserName As String, Optional Password As String) As Boolean
On Error GoTo ErrHandler
Dim dbCurrent As dao.Database
Dim qdf As dao.QueryDef
Dim rst As dao.Recordset
strConnection = "ODBC;DRIVER={MySQL ODBC 5.3 Unicode Driver};" & _
"Server=" & SERVER & ";" & _
"Port=" & 3306 & ";" & _
"Option=" & 0 & ";" & _
"Database=" & DATABASENAME & ";"
Set dbCurrent = DBEngine(0)(0)
Set qdf = dbCurrent.CreateQueryDef("")
With qdf
.Connect = strConnection & _
"Uid=" & USERNAME & ";" & _
"Pwd=" & PWD
.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 Function
ErrHandler:
InitConnect = False
MsgBox Err.Description & " (" & Err.Number & ") encountered", _
vbOKOnly + vbCritical, "InitConnect"
Resume ExitProcedure
Resume
End Function
Appreciated.
Jeff