Warehouse13
asked on
Operation is not allowed when the object is open
Private Sub btnSearch_Click()
Dim objConn As ADODB.Connection
Dim objRST As ADODB.Recordset
Dim strSQL As String
Dim strConn As String
Dim strLicense As String
'Create the ADODB Connection and Recordset objects
Set objConn = CreateObject("ADODB.Connec tion")
Set objRST = CreateObject("ADODB.Record set")
'Open the ADODB Connection
strConn = "provider=Microsoft.ACE.OL EDB.12.0;D ata Source=C:\Documents and Settings\USER\Desktop\Imag es\databas e.mdb;"
strLicense = InputBox("Please enter the license number", "Enter License Number")
strSQL = "Select * from IndexData WHERE Field2 = '" & strLicense & "';"
objConn.Open (strConn)
objConn.Mode = adModeRead
objRST.Open strSQL, objConn, adOpenForwardOnly, adLockOptimistic
objRST.MoveFirst
'Print relevant provider information
While Not objRST.EOF
Debug.Print objRST.Fields("Field2")
Debug.Print objRST.Fields("Field1")
Debug.Print objRST.Fields("Field3")
Debug.Print objRST.Fields("DOCID")
Debug.Print objRST.Fields("DISK")
Debug.Print objRST.Fields("ImagePath")
objRST.MoveNext
Wend
objRST.Close
objConn.Close
'Release the variables
Set objRST = Nothing
Set objConn = Nothing
End Sub
OBJCONN.MODE is where the error is occuring at. I am very new to VBA and haven't been in a VB class in over 7 yrs so any help would be greatly appreciated!
Dim objConn As ADODB.Connection
Dim objRST As ADODB.Recordset
Dim strSQL As String
Dim strConn As String
Dim strLicense As String
'Create the ADODB Connection and Recordset objects
Set objConn = CreateObject("ADODB.Connec
Set objRST = CreateObject("ADODB.Record
'Open the ADODB Connection
strConn = "provider=Microsoft.ACE.OL
strLicense = InputBox("Please enter the license number", "Enter License Number")
strSQL = "Select * from IndexData WHERE Field2 = '" & strLicense & "';"
objConn.Open (strConn)
objConn.Mode = adModeRead
objRST.Open strSQL, objConn, adOpenForwardOnly, adLockOptimistic
objRST.MoveFirst
'Print relevant provider information
While Not objRST.EOF
Debug.Print objRST.Fields("Field2")
Debug.Print objRST.Fields("Field1")
Debug.Print objRST.Fields("Field3")
Debug.Print objRST.Fields("DOCID")
Debug.Print objRST.Fields("DISK")
Debug.Print objRST.Fields("ImagePath")
objRST.MoveNext
Wend
objRST.Close
objConn.Close
'Release the variables
Set objRST = Nothing
Set objConn = Nothing
End Sub
OBJCONN.MODE is where the error is occuring at. I am very new to VBA and haven't been in a VB class in over 7 yrs so any help would be greatly appreciated!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I have no idea. The book told me to...is the book evil?
>> ...is the book evil?
If you burn it, and the flames are an eerie shade of red, then I would say yes. :)
If you burn it, and the flames are an eerie shade of red, then I would say yes. :)
You are opening the connection on the line before. The Mode default is admodeRead, why are you setting that property? Is it needed?
http://msdn.microsoft.com/en-us/library/ms676693%28VS.85%29.aspx