When I try to open the form, it gives me the error:
"The connection cannot be used to perform this operation. It is either closed or invalid in this context."
Here is the code for the On_Load event for the form:
Private Sub Form_Load()
On Error GoTo Form_Load_Err
Dim CurConn As New ADODB.Connection
Dim rst As New ADODB.Recordset
Dim CurDB As Database
Set CurDB = CurrentDb
Set CurConn = New ADODB.Connection
With CurConn
.Provider = "Microsoft.Jet.OLEDB.4.0"
.ConnectionString = "data source= " & CurDB.Name
.Open
End With
Set rst = New ADODB.Recordset
rst.CursorType = adOpenDynamic
rst.LockType = adLockOptimistic
'something is wrong here
rst.Open "SELECT WSPECS.*, WSPECS.
"The connection cannot be used to perform this operation. It is either closed or invalid in this context."
Here is the code for the On_Load event for the form:
Private Sub Form_Load()
On Error GoTo Form_Load_Err
Dim CurConn As New ADODB.Connection
Dim rst As New ADODB.Recordset
Dim CurDB As Database
Set CurDB = CurrentDb
Set CurConn = New ADODB.Connection
With CurConn
.Provider = "Microsoft.Jet.OLEDB.4.0"
.ConnectionString = "data source= " & CurDB.Name
.Open
End With
Set rst = New ADODB.Recordset
rst.CursorType = adOpenDynamic
rst.LockType = adLockOptimistic
'something is wrong here
rst.Open "SELECT WSPECS.*, WSPECS.
NUMBER said:, WSPECS.[ITEM NUMBER] FROM WSPECS INNER JOIN INSSPECS ON (WSPECS.NUMBER said:= INSSPECS.NUMBER said:) AND (WSPECS.[ITEM NUMBER] = INSSPECS.[ITEM NUMBER]) WHERE (((WSPECS.NUMBER said:)=[forms]![start]!number said:) AND ((WSPECS.[ITEM NUMBER])=[forms]![start]![item number]))", CurConn, , , adCmdText
Me![Text0] = rst!number said:Me![Text2] = rst![item number]
Me![Text4] = rst![Nick]
rst.Update
rst.Close
Form_Load_Exit:
Exit Sub
Form_Load_Err:
MsgBox Err.Description
Resume Form_Load_Exit
End Sub
When I change the SQL statement for rst.Open to something like
SELECT * FROM WSPECS WHERE "number said:= '" & "something" & "'"
the code runs perfectly.
I was wondering maybe there's something wrong with the syntax of the rst.open statement.
The SQL statement I have specified in the code should be correct since it was generated using MS ACCESS.
Thanks in advance.