One button opens form based on If

CanWest

Registered User.
Local time
Yesterday, 17:21
Joined
Sep 15, 2006
Messages
272
Hi I am having some trouble with the following code.

The if statement generates a Runtime error 424 Object Required error.
I have shecked this forum for references to Runtim error 424 and have not found anything relevent

Code:
Private Sub cmdViewReport_Click()
[B][COLOR="Red"]If Forms![frm_MainMenu]![sfrm_Reports].Form![cboSelectJobs] Is Null Then[/COLOR][/B]
On Error GoTo Err_cmdViewReport_Click

    Dim stDocName As String
    Dim stLinkCriteria As String

    stDocName = "pfrm_CompanyList"
    DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_cmdViewReport_Click:
    Exit Sub

Err_cmdViewReport_Click:
    MsgBox Err.Description
    Resume Exit_cmdViewReport_Click
Else
On Error GoTo Err_cmdViewReportWithJobs_Click

    Dim stDocName2 As String
    Dim stLinkCriteria2 As String

    stDocName2 = "pfrm_CompanyListWithJobs"
    DoCmd.OpenForm stDocName, , , stLinkCriteria2

Exit_cmdViewReportWithJobs_Click:
    Exit Sub

Err_cmdViewReportWithJobs_Click:
    MsgBox Err.Description
    Resume Exit_cmdViewReportWithJobs_Click

End If

End Sub

I have tried .....
Code:
Forms![frm_MainMenu]![sfrm_Reports].Form![cboSelectJobs]

as well as
Code:
me.cboSelectJobs

in the if statement but get the same error every time.

Any assistance would be greatly appreciated.
 
the correct syntax for addressing a subform is:

Forms![MainFormName]![SubFormControlName].Form![cboSelectJobs]

The subformcontrolname is the name of the subform placeholder control NOT the name of the subform (unless they are the same). cboSelectJobs sounds like a combobox or possibly a multiselect listbox. If this is the case use the ListIndex = -1 to test for null on a combobox and on a multislect listbox you would need to use selecteditems = 0.
 
the correct syntax for addressing a subform is:

Forms![MainFormName]![SubFormControlName].Form![cboSelectJobs]

The subformcontrolname is the name of the subform placeholder control NOT the name of the subform (unless they are the same). cboSelectJobs sounds like a combobox or possibly a multiselect listbox. If this is the case use the ListIndex = -1 to test for null on a combobox and on a multislect listbox you would need to use selecteditems = 0.

The subformcontrolname and the name of the subfor are the same. Saves confusion

cboSelectJobs is a conbo box so I used
Code:
If Forms!frm_MainMenu!sfrm_Reports.Form!cboSelectJobs.ListIndex = -1 Then

This worked perfect for the if part of the statement but the else part of the statement still produces the same error
 
The issue is this line:
Code:
DoCmd.OpenForm stDocName, , , stLinkCriteria2

the form name held in stDocName will be Null because you have not set its value. You set a value for stDocName2 ;-
Code:
stDocName[B]2[/B] =  "pfrm_CompanyListWithJobs"

so either use stDocName OR stDocName2
 
The issue is this line:
Code:
DoCmd.OpenForm stDocName, , , stLinkCriteria2

the form name held in stDocName will be Null because you have not set its value. You set a value for stDocName2 ;-
Code:
stDocName[B]2[/B] =  "pfrm_CompanyListWithJobs"

so either use stDocName OR stDocName2

Yeah, I missed that.
Many thanks
 

Users who are viewing this thread

Back
Top Bottom