B
Billy B
In my reading, I came to believe that once you opened a connection (in this
case in an access 2000 form) the connection remained open until the form was
closed. The code below gives me an error in the click event indicating that
there is no open connection. Thank you.
Option Compare Database
Private Sub Form_Load()
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Set cn = CurrentProject.AccessConnection
Set rs = New ADODB.Recordset
End Sub
Private Sub cmdTest_Click()
'after entering data and clicking button, update the table
With rs
.Source = "Select * from tblTest"
.LockType = adLockOptimistic
.CursorType = adOpenKeyset
.Open
End With
With rs
If Not (rs.BOF And rs.EOF) Then
.AddNew
.Fields("TestLine1").Value = Me.txtLine1.Value
.Fields("TestLine2").Value = Me.txtLine2.Value
.Update
Else
.AddNew
.Fields("TestLine1").Value = Me.txtLine1.Value
.Fields("TestLine2").Value = Me.txtLine2.Value
.Update
End If
End With
Set rs = Nothing
set cn = nothing
Me.txtLine1.Value = ""
Me.txtLine2.Value = ""
End Sub
case in an access 2000 form) the connection remained open until the form was
closed. The code below gives me an error in the click event indicating that
there is no open connection. Thank you.
Option Compare Database
Private Sub Form_Load()
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Set cn = CurrentProject.AccessConnection
Set rs = New ADODB.Recordset
End Sub
Private Sub cmdTest_Click()
'after entering data and clicking button, update the table
With rs
.Source = "Select * from tblTest"
.LockType = adLockOptimistic
.CursorType = adOpenKeyset
.Open
End With
With rs
If Not (rs.BOF And rs.EOF) Then
.AddNew
.Fields("TestLine1").Value = Me.txtLine1.Value
.Fields("TestLine2").Value = Me.txtLine2.Value
.Update
Else
.AddNew
.Fields("TestLine1").Value = Me.txtLine1.Value
.Fields("TestLine2").Value = Me.txtLine2.Value
.Update
End If
End With
Set rs = Nothing
set cn = nothing
Me.txtLine1.Value = ""
Me.txtLine2.Value = ""
End Sub