When I try to run my program it says run-time error 3709 the connection cannot be used to perform this action, it is either closed or invalid in this context. mean while I used a module in which i put the following codes :
Public cn As ADODB.Connection
Public Sub Main()
Dim cn As ADODB.Connection
Set cn = New ADODB.Connection
cn.ConnectionString = "C:UsersLab2c28DocumentsAuthors databaseauthors.mdb"
cn.Open
Form1.Show
End Sub
and then I put the following codes in a save button :
Private Sub cmdsave_Click()
Dim rsauthors As New ADODB.Recordset
Set rsauthors = New ADODB.Recordset
With rsauthors:
-
ActiveConnection = cn
- Source = ("SElect * From authors")
.
- LockType = adLockOptimistic
- Open
End With
With rsauthors:
- AddNew
- Fields("Book ID_") = Text1.Text
- Fields("Name") = Text2.Text
- Update
End With
End Sub
Please help me
Software/Hardware used:
VB6
ASKED:
October 11, 2012 2:08 PM
UPDATED:
October 11, 2012 3:04 PM
Before trying to execute operations on the database you need to check whether the connection was successfully established, but in this case I don’t see where you tell the connection object the the driver or type of database you are using, and thus I don’t think you will be able to connect.