odbc system dsn problem hope you can help
I'm trying to set up a system using the odbc drivers so that the front and back end can work over any network once the odbc has been set.
However at the moment I keep getting an error message about the odbc not having the correct parameters ( amount expected = 2) when I try to open a recordset. The other errors it generates relate to the object being closed which I realised is due to the fact that the connection is opening for some reason.
I'm using the code from chapter 12 of beginning access vba as a base for my system.
gcnconn is a global variable declared as a connection
gstrconnection is a global string variable
I've watched the variables and stepped through the code from when the form opens. Each section other than the processrecordset function seems to works fine and returns the results as expected.
The odbc is set up under system dsn as far as I can tell correctly. I seperated out the lines just to see if it was something i'd done in the writing of a single line.
The connection code is:
Sub opendbconnection()
On Error GoTo Handleerror
gstrconnection = "ODBC;DSN=compcontrol;"
'create a new connection instance and open it using the connection
'string
Set gcnconn = New ADODB.Connection
With gcnconn
.Provider = "MSDASQL"
.Properties("Data Source").value = gstrconnection
.Open
End With
Exit Sub
Handleerror:
generalerrorhandler Err.Number, Err.Description, "modstartup", "opendbconnection"
Exit Sub
End Sub
Function processrecordset(strsqlstatement As String) As ADODB.Recordset
On Error GoTo Handleerror
'open the connection to the database
Call opendbconnection
'create a new instance of a recordset
Dim rscont As New ADODB.Recordset
'set various properties of the recordset
With rscont
'specify a cursortype and locktype that will allow updates
.CursorType = adOpenKeyset
.CursorLocation = adUseClient
.LockType = adLockBatchOptimistic
.ActiveConnection = gcnconn
.Source = strsqlstatement
'populate
.Open
'disconnect the recordset
.ActiveConnection = Nothing
'sort the recordset
End With
rscont.Open
'close the connection to the database
Call closedbconnection
'return the recordset
Set processrecordset = rscont
Exit Function
Handleerror:
generalerrorhandler Err.Number, Err.Description, "moddblogic", "processrecordset"
Exit Function
End Function
I've looked all over the web for setting up the connections within vba and within odbc and as far as I can tell its right so please help resolve this issue
|