Update or CancelUpdate without AddNew or Edit. (Error 3020)

G

Guest

Hi All,

I Get this error message when I open a form and want to move to a new field.

Update or CancelUpdate without AddNew or Edit. (Error 3020)

I have a list box on the form that list the records in the table and as I
use the record navigation bar I want it to select the current record in the
list box, also if the user selects the record in the list box, I want it to
update the fields in the form.

Below is the events and the code associated with the events.
The code may be a bit clumsy as I am prototyping at the moment and will
clean up later once it is working.

I have traced it to the Form_Current() event, and the line where I select
the row in the list box; lstEntries.Selected(i) = True

I cannot see why it would want to call an update or cancelupdate when all i
am doing is selecting the record.

I would appreciate some insight into this as it is very irritating that I
cannot seem to resolve the issue.

<--- CODE START -->
Option Compare Database
Dim bNav As Boolean
Dim bLoad As Boolean

Private Sub DESCRIPTION_KeyPress(KeyAscii As Integer)
On Error GoTo ErrorCondition
Dim iPos As Integer
If KeyAscii >= 97 And KeyAscii <= 122 Then
KeyAscii = KeyAscii - 32
End If
GoTo Completed
ErrorCondition:
MsgBox Err.DESCRIPTION, vbCritical, "DESCRIPTION_KeyPress"

Completed:

End Sub

Private Sub Form_AfterUpdate()
On Error GoTo ErrorCondition
DESCRIPTION.Requery
lstEntries.Requery
GoTo Completed
ErrorCondition:
MsgBox Err.DESCRIPTION, vbCritical, "Form_AfterUpdate"

Completed:

End Sub

Private Sub Form_Current()
On Error GoTo ErrorCondition
Dim rs As Object
Set rs = Me.Recordset.Clone
If IsNull(rs.[ID].Value) Then
Exit Sub
End If
If Not bNav Then
Dim dDate As Date
Dim lId As Long
dDate = rs.[DATE].Value
lId = rs.[ID].Value
If lstEntries.Column(1) = dDate And lstEntries.Column(2) = lId Then
Else
Dim i As Integer
For i = 0 To lstEntries.ListCount - 1
If lstEntries.ItemData(i) = Trim(Str(lId)) Then
bNav = True
lstEntries.Selected(i) = True
Exit For
End If
Next
End If
Else
bNav = False
End If
GoTo Completed
ErrorCondition:
MsgBox Err.DESCRIPTION, vbCritical, "Form_Current"

Completed:
On Error Resume Next
If Not bLoad Then
Me![DATE].SetFocus
End If
bLoad = False
End Sub

Private Sub Form_Open(Cancel As Integer)
On Error GoTo ErrorCondition
bLoad = True
GoTo Completed
ErrorCondition:
MsgBox Err.DESCRIPTION, vbCritical, "Form_Exit"

Completed:

End Sub

Private Sub lstEntries_AfterUpdate()
On Error GoTo ErrorCondition
If Not bNav Then
If UCase(Me![lstEntries].Value) <> "#DELETED" Then
' Find the record that matches the control.
bNav = True
Dim rs As Object
Set rs = Me.Recordset.Clone
rs.FindFirst "[ID] = " & Str(Nz(Me![lstEntries], 0))
If Not rs.EOF Then
Me.Bookmark = rs.Bookmark
End If
' Change the field to upper case to catch the data entered before
' I had implemented the key press event
DESCRIPTION = UCase(DESCRIPTION)

Else
Dim sSource As String
Dim iIndex As Integer
iIndex = lstEntries.ListIndex
sSource = lstEntries.RowSource
lstEntries.RowSource = ""
lstEntries.RowSource = sSource
On Error Resume Next
lstEntries.Selected(iIndex) = True
End If
Else
bNav = False
End If
GoTo Completed

ErrorCondition:
MsgBox Err.DESCRIPTION, vbCritical, "lstEntries_AfterUpdate"

Completed:
End Sub

Private Sub PettyCashLines_Exit(Cancel As Integer)
On Error GoTo ErrorCondition
Call Form_AfterUpdate
GoTo Completed

ErrorCondition:
MsgBox Err.DESCRIPTION, vbCritical, "PettyCashLines_Exit"

Completed:

End Sub
Private Sub cmdNewRecord_Click()
On Error GoTo Err_cmdNewRecord_Click
DoCmd.GoToRecord , , acNewRec
DATE.SetFocus
Exit_cmdNewRecord_Click:
Exit Sub

Err_cmdNewRecord_Click:
MsgBox Err.DESCRIPTION, vbCritical, "cmdNewRecord_Click"
Resume Exit_cmdNewRecord_Click

End Sub
Private Sub cmdDelRecord_Click()
On Error GoTo Err_cmdDelRecord_Click


DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70

lstEntries.Requery
Call lstEntries_AfterUpdate

Exit_cmdDelRecord_Click:
Exit Sub

Err_cmdDelRecord_Click:
MsgBox Err.DESCRIPTION, vbCritical, "cmdDelRecord_Click"
Resume Exit_cmdDelRecord_Click

End Sub
Private Sub cmdSaveRecord_Click()
On Error GoTo Err_cmdSaveRecord_Click


DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
Call Form_AfterUpdate
Call Form_Current
Exit_cmdSaveRecord_Click:
Exit Sub

Err_cmdSaveRecord_Click:
MsgBox Err.DESCRIPTION, vbCritical, "cmdSaveRecord_Click"
Resume Exit_cmdSaveRecord_Click

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top