J
John Melbourne
Hi All,
I have a table with a single record that contains the dates and
information for the jobs processed during a quarters processing, I want to
create a form so that users can update the table.
The table "tblQuarterDates" contains the following fields.
fldPreQuarterStart
fldPreQuarterEnd
fldCurQuarterStart
fldCurQuarterEnd
I have created a form with 4 fields Unbounded and I have the following code.
Option Compare Database
Option Explicit
'----------------------------------------------------------------------------------------
Private Sub Command0_DblClick(Cancel As Integer)
' Close the form
DoCmd.Close
End Sub
'
----------------------------------------------------------------------------------------
Private Sub Form_Load()
Dim rst As ADODB.Recordset
Set rst = New ADODB.Recordset
rst.ActiveConnection = CurrentProject.Connection
rst.CursorType = adOpenKeyset
rst.CursorLocation = adUseClient
'rst.LockType = adLockReadOnly
rst.Open "Select * from tblQuarterDates", Options:=adCmdText
' Set the form's recordset to the recordset just created
Set Me.Recordset = rst
' Move to the first record
' If at bof, move to the next record
If Me.Recordset.BOF Then
Me.Recordset.MoveNext
End If
Me.txtPrevoiusQuarterStartDate =
rsUpdate.Fields.Item("fldPreQuarterStart")
Me.txtPreviousQuarterEndDate =
rsUpdate.Fields.Item("fldPreQuarterEnd")
Me.txtCurrentQuarterDateText =
rsUpdate.Fields.Item("fldCurQuarterStart")
End Sub
'
-----------------------------------------------------------------------------------------
Private Sub txtExit_Click()
DoCmd.Close
End Sub
Private Sub txtUpdate_DblClick(Cancel As Integer)
' Update the End of quarter control file
' written by JM
'
Dim sql As String
Dim rsUpdate As ADODB.Recordset
Set rsUpdate = New ADODB.Recordset
On Error GoTo DbError
'Assign updatable cursor and lock type properties.
rsUpdate.CursorType = adOpenDynamic
rsUpdate.LockType = adLockOptimistic
'Open the Recordset object.
rsUpdate.Open "Select * from tblQuarterDates", Options:=adCmdText
'Don't try to update the record, if the recordset
' did not find a row.
If rsUpdate.EOF = False Then
' Update the record based on the input.
With rsUpdate
Me.txtPrevoiusQuarterStartDate =
rsUpdate.Fields.Item("fldPreQuarterStart")
Me.txtPreviousQuarterEndDate =
rsUpdate.Fields.Item("fldPreQuarterEnd")
Me.txtCurrentQuarterDateText =
rsUpdate.Fields.Item("fldCurQuarterStart")
.Update
.Close
End With
End If
MsgBox "Record update.", vbInformation
' Close the form-level Recordset object and
' refresh it to include the newly update row.
rsUpdate.Close
Exit Sub
DbError:
MsgBox "There was an error updating the database. " _
& Err.Number & ", " & Err.Description
End Sub
When I run the Update I get the following message:
First sentence come from my error routine.
There was an error updating the database. 3709, The connection cannot be
used to perform this operation. It is either closed or invalid in this
context.
Any help welcome.
Thanks in advance.
I have a table with a single record that contains the dates and
information for the jobs processed during a quarters processing, I want to
create a form so that users can update the table.
The table "tblQuarterDates" contains the following fields.
fldPreQuarterStart
fldPreQuarterEnd
fldCurQuarterStart
fldCurQuarterEnd
I have created a form with 4 fields Unbounded and I have the following code.
Option Compare Database
Option Explicit
'----------------------------------------------------------------------------------------
Private Sub Command0_DblClick(Cancel As Integer)
' Close the form
DoCmd.Close
End Sub
'
----------------------------------------------------------------------------------------
Private Sub Form_Load()
Dim rst As ADODB.Recordset
Set rst = New ADODB.Recordset
rst.ActiveConnection = CurrentProject.Connection
rst.CursorType = adOpenKeyset
rst.CursorLocation = adUseClient
'rst.LockType = adLockReadOnly
rst.Open "Select * from tblQuarterDates", Options:=adCmdText
' Set the form's recordset to the recordset just created
Set Me.Recordset = rst
' Move to the first record
' If at bof, move to the next record
If Me.Recordset.BOF Then
Me.Recordset.MoveNext
End If
Me.txtPrevoiusQuarterStartDate =
rsUpdate.Fields.Item("fldPreQuarterStart")
Me.txtPreviousQuarterEndDate =
rsUpdate.Fields.Item("fldPreQuarterEnd")
Me.txtCurrentQuarterDateText =
rsUpdate.Fields.Item("fldCurQuarterStart")
End Sub
'
-----------------------------------------------------------------------------------------
Private Sub txtExit_Click()
DoCmd.Close
End Sub
Private Sub txtUpdate_DblClick(Cancel As Integer)
' Update the End of quarter control file
' written by JM
'
Dim sql As String
Dim rsUpdate As ADODB.Recordset
Set rsUpdate = New ADODB.Recordset
On Error GoTo DbError
'Assign updatable cursor and lock type properties.
rsUpdate.CursorType = adOpenDynamic
rsUpdate.LockType = adLockOptimistic
'Open the Recordset object.
rsUpdate.Open "Select * from tblQuarterDates", Options:=adCmdText
'Don't try to update the record, if the recordset
' did not find a row.
If rsUpdate.EOF = False Then
' Update the record based on the input.
With rsUpdate
Me.txtPrevoiusQuarterStartDate =
rsUpdate.Fields.Item("fldPreQuarterStart")
Me.txtPreviousQuarterEndDate =
rsUpdate.Fields.Item("fldPreQuarterEnd")
Me.txtCurrentQuarterDateText =
rsUpdate.Fields.Item("fldCurQuarterStart")
.Update
.Close
End With
End If
MsgBox "Record update.", vbInformation
' Close the form-level Recordset object and
' refresh it to include the newly update row.
rsUpdate.Close
Exit Sub
DbError:
MsgBox "There was an error updating the database. " _
& Err.Number & ", " & Err.Description
End Sub
When I run the Update I get the following message:
First sentence come from my error routine.
There was an error updating the database. 3709, The connection cannot be
used to perform this operation. It is either closed or invalid in this
context.
Any help welcome.
Thanks in advance.