Error Handling

Lynn_AccessUser

Registered User.
Local time
Today, 14:01
Joined
Feb 4, 2003
Messages
125
I have a main form that on the click event on a button it opens up another form. However, there may not be any records in the second table related to the primary ID of the main form so it gives me the following error:

run- time error 2455
You entered an expression that has a invalid reference to the property Form/Report.

I wrote the following code to handle the error:

On Error GoTo Err_Form_Load

Proc_Exit:
Exit Sub

Err_Form_Load:
MsgBox "There Is Data"
GoTo Proc_Exit

The message box appears, but when you click OK and close the msgBox the second form opens. How can I prevent this from happening.

Thanks!!!!!!!1
 
Posting the full code might have been better as it allows us to see what you are actually doing.

Code:
On Error GoTo Err_Form_Load 

Proc_Exit: 
    Exit Sub 

Err_Form_Load: 
    MsgBox "There Is Data" 
    Resume Proc_Exit

You say your error occurs if there is no data yet your post, when the error happens, says "There is data!" - is this just a typo?
 
Oops sorry . . . yes a typo.

The code on the click event on the main form is:

Private Sub OpenSettlement_Click()
On Error GoTo Err_OpenSettlement_Click

Dim stDocName As String
Dim stLinkCriteria As String

If LastName.Locked = False Then
DoCmd.RunCommand acCmdSaveRecord
DoCmd.OpenForm "frm_Settlement", , , stLinkCriteria
Else
DoCmd.OpenForm "frm_Settlement", , , stLinkCriteria, , , "ReadOnly"
End If

Exit_OpenSettlement_Click:
Exit Sub

Err_OpenSettlement_Click:
MsgBox Err.Description
Resume Exit_OpenSettlement_Click

End Sub

The code on the on load event of the second form is:

Private Sub Form_Load()

On Error GoTo Err_Form_Load

If IsNull(Me!SettlementData) Or Me!SettlementData = "" Then
Detail.Visible = False
ElseIf Me!SettlementData = 0 Then
Detail.Visible = False
Else
Detail.Visible = True
SettlementData.Visible = False
End If

If Me.OpenArgs = "ReadOnly" Then
Me.AmountOfDeposit.Locked = True
Me.AmountOfDeposit.BackColor = -2147483633
'Similar code as above for all of the fields on the form
End If

Proc_Exit:
Exit Sub

Err_Form_Load:
If Err.Number = 2455 Then
MsgBox "There Is No Settlement Data"
Else
MsgBox Err.Description
End If
GoTo Proc_Exit

End Sub
 

Users who are viewing this thread

Back
Top Bottom