How to fix run-time error 3709 with my computer

5 pts.
Tags:
Visual Basic 6
Visual Basic Error Messages
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

Answer Wiki

Thanks. We'll let you know when a new response is added.

You could use something like i have done below.
Public adoDatabase As New ADODB.Connection
Dim rst As ADODB.Recordset

Private Sub Form_Load()
Set rst = New ADODB.Recordset
rst.Open “Reprocess”, adoDatabase, adOpenKeyset, adLockOptimistic, adCmdTable
txtMName.Text = rst(“ManufacturerName”).Value
txtMSno.Text = rst(“MFR_SL_NO”).Value
cboVirology.Text = rst(“volume”).Value
rst(“row_upd_date”).Value = CDate(Now)
rst(“user_id”).Value = pUserID

For Create:
Set rst = New ADODB.Recordset
    rst.Open “Reprocess”, adoDatabase, adOpenKeyset, adLockOptimistic, adCmdTable
    rst.AddNew
    txtMName.Text = “”
    txtMSno.Text = “”
    cboVirology.Text = “”
   
For Save:
rst(“ManufacturerName”).Value = txtMName.Text
rst(“MFR_SL_NO”).Value = txtMSno.Text
rst(“volume”).Value = cboVirology.Text
rst(“row_upd_date”).Value = CDate(Now)
rst(“user_id”).Value = pUserID
rst.Update
MsgBox “The record is saved successfully”, , “UPDATE”

<code/>

Here Reprocess is one of my tables in my Database. I hope you will customize the thnig i have given you according to your needs. Wish you luck any doudts ask me.

Discuss This Question: 1  Reply

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • carlosdl
    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.
    69,510 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following