Run time error '2001' You cancelled the previous operation

  • Thread starter Thread starter Jack
  • Start date Start date
J

Jack

Hi,
My data entry form was working just fine until I loaded the production data.
Now I am getting the above error

I cannot figure out why this is happening.

The error is happening in the following code:
Private Sub cboPlants_AfterUpdate()
'On Error GoTo Err_cboPlants_AfterUpdate
Dim strPlants As String
Dim strYear As String
Dim TheDate As Date
Dim strKey As Integer

'Code added

If IsNull(cboPlants) Then
Exit Sub
End If
If IsNull(Me!cboSource1) Then
MsgBox ("Please select the Source")
Me!cboSource1.SetFocus
Else

TheDate = Now()
strPlants = Me!txtPlantCode
strYear = Right(DatePart("yyyy", TheDate), 2)


Me!IDNum = strPlants & strYear

DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
'DoCmd.DoMenuItem acFormBar, acRecordsMenu, 5, , acMenuVer70
strKey = Me.txtKey.Value
Me.IDNum.Value = strPlants & strYear & "-" & strKey
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acRecordsMenu, 5, , acMenuVer70

End If

Me.cboProductType.Visible = True

Exit Sub

'MsgBox Err.Description
'Resume Exit_cboPlants_AfterUpdate

End Sub


Also the code stops running in the following line:
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70

I appreciate any help for resolution of this issue. Thanks.
 
Hi Jack,
this error is occurring when one of the lines of code fails to work.
To find out which line is causing the problem, set a break point and step
through the code.

By the way, the following code-->
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
'DoCmd.DoMenuItem acFormBar, acRecordsMenu, 5, , acMenuVer70

Is quite old type of code, typical wizard generated code, written like that
for backward compatibility.

It is difficult to know what each line of that code is meant to do.
To save a record, we usually use code like this-->
If Me.Dirty = True Then
Me.Dirty = False
End If

What is this line meant to do?
'DoCmd.DoMenuItem acFormBar, acRecordsMenu, 5, , acMenuVer70



Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia
 
Thanks for your help Jeanetter. I appreciate it.

When I am going though the break point I am getting the error in the second
line
To be honest I do not know what's going on here. I inherited some old system
which I am trying to upgrade. I will try the other method of saving as you
are recommending.
Thanks.
 
Back
Top