Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Object required error when trying to reference form

Status
Not open for further replies.

SmokeEater

Technical User
Feb 14, 2002
90
CA
I have created this function
Code:
Function Shopex_ind(myForm)
        On Error GoTo Err_Shopex_ind
Dim Shopex
    Shopex = ""
    
                If myForm![Shop1] = -1 Then
                    Shopex = 1
                    myForm![Shop1Label].BackColor = 65280
                    myForm![Shop 01] = 1
                Else
                    myForm![Shop1Label].BackColor = 255
                    myForm![Shop 01] = 0
                End If
                
           Shopex_ind = Shopex

                
                
Exit_Shopex_ind:
    Exit Function

Err_Shopex_ind:
    MsgBox Err.Description
    Resume Exit_Shopex_ind

End Function

I get an object required error with it. How do I properly reference the form object?
 
I see several issues with what I would consider good practice in coding.
1a) The function has no return data type.
1b) myForm has no type associated with it.
Function Shopex_ind(myForm as Form) as Long

2) Shopex has no data type dim'd with it. I wouldn't set it to either "" (string) or 1 (numeric).

3) you don't have any comments in your code.

Your code assumes myForm is actually a form object. If you are sending a form name, then you will have to try lameid's suggestion.

Duane
Hook'D on Access
MS Access MVP
 
Thank you both for your suggestions. In going through the code and tidying it up I found a typo on the form which was calling the function. All now works as it should.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top