Hello:
I have a form that is designed to add new records to a table in my Access 2003/2000 data compatible database.
My problem is that my OnCurrent event is triggering an Error #3021, "No Current Record" and while my error trap is catching it, I'd like to be able to handle it.
The problem stems from the fact that there are NO records in the table at this point. This will not be a problem normally, but I am adding this from the point of view of there being empty tables (a "clean project" as it were).
I'd like to be able to allow the user to choose what to do when this issue occurs, ie: If they want to add new records, then just not open this form and be taken to the other form to add them, or if they don't want to create new records, just exit, possibly with some sort of info. message box.
Unfortunately, I just can't solve this one by sticking in "Cancel=True" in the OnOpen event because that is NOT where the 3021 error is firing.
Different variations of code I am trying always force me to exit the sub and allow the form to open with no record, and that is not what I want. I'd prefer to not open it at all if I can.
Here is a sample of the code I am trying to use in the OnCurrent event:
-- code block begins here --
Private Sub Form_Current()
On Error GoTo Err_Form_Current
Dim FiltCount As Integer, FiltCurrent As Integer
Dim Lab1 As String
Dim Lab2 As String
Me.Refresh
Me.RecordsetClone.MoveLast
FiltCount = Me.RecordsetClone.RecordCount
FiltCurrent = Me.CurrentRecord
Lab1 = FiltCurrent
Lab2 = FiltCount
Me.xofLbl.Caption = Lab1
Me.ofxLbl.Caption = Lab2
Exit_Form_Current:
Exit Sub
Err_Form_Current:
Select Case (Err.Number)
Case 3021
' Code to create new records here - handle no records status..
Dim AX As Variant
AX = MsgBox("No values present. Do you wish to ADD new records now?", vbYesNo, "No Records Available to Edit")
If AX = vbYes Then
' go to AddForm with parameter to close this form..
DoCmd.OpenForm "AddForm", acNormal, , , acFormPropertySettings, acWindowNormal, "AF"
Resume Exit_Form_Current
Else
' NOTE: Generates an error 2585, can't exit or close?
' This would work in an OnOpen, but here?
Cancel = True
DoCmd.Close
End If
Case Else
MsgBox Err.Number & ": " & Err.Description, vbInformation
Resume Exit_Form_Current
End Select
End Sub
-- code block ends here --
Suggestions? There is only an OnOpen event and this OnCurrent event, and the OnOpen event is merely checking for args passed through from other forms - nothing fancy.
Thanks,
marcus101
Access/SQL/XML Developer
Ottawa, Canada
I have a form that is designed to add new records to a table in my Access 2003/2000 data compatible database.
My problem is that my OnCurrent event is triggering an Error #3021, "No Current Record" and while my error trap is catching it, I'd like to be able to handle it.
The problem stems from the fact that there are NO records in the table at this point. This will not be a problem normally, but I am adding this from the point of view of there being empty tables (a "clean project" as it were).
I'd like to be able to allow the user to choose what to do when this issue occurs, ie: If they want to add new records, then just not open this form and be taken to the other form to add them, or if they don't want to create new records, just exit, possibly with some sort of info. message box.
Unfortunately, I just can't solve this one by sticking in "Cancel=True" in the OnOpen event because that is NOT where the 3021 error is firing.
Different variations of code I am trying always force me to exit the sub and allow the form to open with no record, and that is not what I want. I'd prefer to not open it at all if I can.
Here is a sample of the code I am trying to use in the OnCurrent event:
-- code block begins here --
Private Sub Form_Current()
On Error GoTo Err_Form_Current
Dim FiltCount As Integer, FiltCurrent As Integer
Dim Lab1 As String
Dim Lab2 As String
Me.Refresh
Me.RecordsetClone.MoveLast
FiltCount = Me.RecordsetClone.RecordCount
FiltCurrent = Me.CurrentRecord
Lab1 = FiltCurrent
Lab2 = FiltCount
Me.xofLbl.Caption = Lab1
Me.ofxLbl.Caption = Lab2
Exit_Form_Current:
Exit Sub
Err_Form_Current:
Select Case (Err.Number)
Case 3021
' Code to create new records here - handle no records status..
Dim AX As Variant
AX = MsgBox("No values present. Do you wish to ADD new records now?", vbYesNo, "No Records Available to Edit")
If AX = vbYes Then
' go to AddForm with parameter to close this form..
DoCmd.OpenForm "AddForm", acNormal, , , acFormPropertySettings, acWindowNormal, "AF"
Resume Exit_Form_Current
Else
' NOTE: Generates an error 2585, can't exit or close?
' This would work in an OnOpen, but here?
Cancel = True
DoCmd.Close
End If
Case Else
MsgBox Err.Number & ": " & Err.Description, vbInformation
Resume Exit_Form_Current
End Select
End Sub
-- code block ends here --
Suggestions? There is only an OnOpen event and this OnCurrent event, and the OnOpen event is merely checking for args passed through from other forms - nothing fancy.
Thanks,
marcus101
Access/SQL/XML Developer
Ottawa, Canada