title: VB 6.0 Run-time error '3709': The connection cannot be used to perform this operation. It is either closed or invalid in this context
body: <p>I'm coding BASIC in VB 6.0. I'm creating a database and there is this one problem I have. This Save button of mine. When I run it and click on the Save button it says </p>
  
  <blockquote>
    <p>"Run-time error '3709':The connection cannot be used to perform this
    operation. It is either closed or invalid in this context"</p>
  </blockquote>
  
  <p><strong>This is my code on the Save Button</strong></p>
  
  <pre class="lang-vb prettyprint-override"><code>Private Sub Command1_Click()
  If rs.State = 1 Then rs.Close
  rs.Open "SELECT *FROM Table1 WHERE FirstName = '" &amp; Text1.Text &amp; "' AND LastName = '" &amp; Text2.Text &amp; "'", db
  If rs.RecordCount &lt;&gt; 0 Then
  MsgBox "RECORD EXISTS"
  Else
  If rs.State = 1 Then rs.Close
  rs.Open "SELECT *FROM Table1", rs
  rs.AddNew
  rs!FirstName = Text1.Text
  rs!LastName = Text2.Text
  rs.Update
  MsgBox "SAVED"
  Text1.Text = ""
  Text2.Text = ""
  End If
  End Sub
  </code></pre>
  
  <p><strong>And this is my code in the Module</strong>
  </p>
  
  <pre><code>Dim Text1, Text2 As String
  Public db As New ADODB.Connection
  Public rs As New ADODB.Recordset
  Public Sub Main()
  Set db = New ADODB.Connection
  db.ConnectionString = "Provider = Microsoft.JET.OLEDB.4.0; " &amp; " Data Source = " &amp; App.Path &amp; "\Database1.mdb"
  db.Open
  rs.LockType = adLockOptimistic
  rs.CursorLocation = adUseClient
  rs.CursorType = adOpenStatic
  Form3.Show
  End Sub
  </code></pre>
  
  <p><strong>And this is the Highlighted code</strong></p>
  
  <pre class="lang-vb prettyprint-override"><code>rs.Open "SELECT *FROM Table1 WHERE FirstName = '" &amp; Text1.Text &amp; "' AND LastName = '" &amp; Text2.Text &amp; "'", db
  </code></pre>