Error 424 Object Required - Subform Launch

ljoekelsoey4

Registered User.
Local time
Today, 10:02
Joined
Mar 16, 2017
Messages
49
Hello, I'm getting the error when clicking on the link "add new" to a seperate form that is used to enter data in the table that is shown via a subform on the page. I'm not sure what has changed exactly, but prior to christmas (when i last worked on this) everything worked fine. >_<


Thanks for your help

EDIT: when a CHI number (id number) has been selected in the main form, if i open the subform from the navigation pane, there is no problem, and I am able to enter and save new data in the corresponding tables. not sure if this is of any help/significance.

Code:
Option Compare Database

Private Sub biopsynewadd_Click()
If CHI Is Null Then
MsgBox "You need to select a patient before you can enter data"
Cancel = True
DoCmd.CancelEvent
Else
DoCmd.OpenForm "frmFontanBiopsyAdd"
End If
End Sub

Private Sub bloodtestnewadd_Click()
If CHI Is Null Then
MsgBox "You need to select a patient before you can enter data"
Cancel = True
DoCmd.CancelEvent
Else
DoCmd.OpenForm "frmFontanBloodTestAdd"
End If
End Sub

Private Sub CTaddnew_Click()
If CHI Is Null Then
MsgBox "You need to select a patient before you can enter data"
Cancel = True
DoCmd.CancelEvent
Else
DoCmd.OpenForm "frmFontanCTAdd"
End If
End Sub

Private Sub elastographyaddnew_Click()
If CHI Is Null Then
MsgBox "You need to select a patient before you can enter data"
Cancel = True
DoCmd.CancelEvent
Else
DoCmd.OpenForm "frmFontanElastographyAdd"
End If
End Sub

Private Sub ultrasoundaddnew_Click()
If CHI Is Null Then
MsgBox "You need to select a patient before you can enter data"
Cancel = True
DoCmd.CancelEvent
Else
DoCmd.OpenForm "frmFontanUltrasoundAdd"
End If
End Sub

Private Sub endoscopyaddnew_Click()
If CHI Is Null Then
MsgBox "You need to select a patient before you can enter data"
Cancel = True
DoCmd.CancelEvent
Else
DoCmd.OpenForm "frmFontanEndoscopyAdd"
End If
End Sub

Private Sub cmdCLOSE_Click()
DoCmd.Close
End Sub
 

Attachments

  • example.jpg
    example.jpg
    72.8 KB · Views: 98
Last edited:
You should be using IsNull(Me.YourCHICombo) as to check for null. The Is Null won't work as you expect and is incorrect syntax in this use in VBA.

If that's not the problem where are you getting the error, what part of the code is highlighted?
 
You should be using IsNull(Me.YourCHICombo) as to check for null. The Is Null won't work as you expect and is incorrect syntax in this use in VBA.

If that's not the problem where are you getting the error, what part of the code is highlighted?

Thank you so much. This forum is endlessly helpful and educational, and i really appreciate it!!
 
You also can't (and don't need to) cancel the click event, and if you use a subroutine, you can refactor your code as follows...
Code:
Private Sub biopsynewadd_Click()
    TestChiAndOpenForm "frmFontanBiopsyAdd"
End Sub

Private Sub bloodtestnewadd_Click()
    TestChiAndOpenForm "frmFontanBloodTestAdd"
End Sub

Private Sub CTaddnew_Click()
    TestChiAndOpenForm "frmFontanCTAdd"
End Sub

Private Sub elastographyaddnew_Click()
    TestChiAndOpenForm "frmFontanElastographyAdd"
End Sub

Private Sub ultrasoundaddnew_Click()
    TestChiAndOpenForm "frmFontanUltrasoundAdd"
End Sub

Private Sub endoscopyaddnew_Click()
    TestChiAndOpenForm "frmFontanEndoscopyAdd"
End Sub

Private Sub TestChiAndOpenForm(FormName As String)
    If IsNull(Me.CHI) Then
        MsgBox "You need to select a patient before you can enter data"
    Else
        DoCmd.OpenForm FormName
    End If
End Sub

Private Sub cmdCLOSE_Click()
    DoCmd.Close
End Sub
hth
Mark
 

Users who are viewing this thread

Back
Top Bottom