Getting"MS Access can't find the object...." error

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • teresedp
    New Member
    • Dec 2010
    • 3

    #1

    Getting"MS Access can't find the object...." error

    Hi--I am trying to get an Access database to print labels NOT starting on the first line of labels (to use up partially-used sheets). I was directed to this MS Knowledge Base article:
    http://support.microso ft.com/kb/299024

    I am not new to Access but am very much a beginner with VBA. I pasted the following code from the KB article in a Standard module in my database:
    Code:
    '*********************************************************
       'Declarations section of the module.
    '**********************************************************
    
    Option Compare Database
    Option Explicit
    
    Dim LabelBlanks&
    Dim LabelCopies&
    Dim BlankCount&
    Dim CopyCount&
    					
    '==========================================================
       ' The following function will cause an input box to
       ' display when the report is run that prompts the user
       ' for the number of used labels to skip and how many
       ' copies of each label should be printed.
    '===========================================================
    
    Function LabelSetup ()
       LabelBlanks& = Val(InputBox$("Enter Number of blank labels to skip"))
       LabelCopies& = Val(InputBox$("Enter Number of Copies to Print"))
       If LabelBlanks& < 0 Then LabelBlanks& = 0
       If LabelCopies& < 1 Then LabelCopies& = 1
    End Function
    
    (There are other functions in the module as well)
    As per the instructions in the KB article, I put
    =LabelSetup()
    in the OnOpen property of my Labels report to call the function.

    When I try to print the report (or see it in Print view), I get the error "Microsoft Access cannot find the object '=LabelSetup(). ' If '=LabelSetup()' is a new macro or macro group, make sure you have saved it and that you have typed its name correctly."

    Here is what I have tried so far:
    (1) Double- and triple-checked that the function in the module and the function call are spelled exactly the same
    (2) Compacted and repaired the database
    (3) Deleted, repasted and recompiled the Standard code module

    and I still get the error.

    These were all things I did through suggestions from an expert on another forum.

    Any other ideas as to why this frustrating thing is happening?

    Thanks in advance.
    teresedp
  • ADezii
    Recognized Expert Expert
    • Apr 2006
    • 8834

    #2
    Where, exactly, is LabelSetup() Declared? It appears that it needs to be Declared Privately in the Report's Class Module.

    Comment

    • teresedp
      New Member
      • Dec 2010
      • 3

      #3
      As I said, I am very inexperienced with VBA--can you tell me where and how to declare it?

      Thanks,
      teresedp

      Comment

      • ADezii
        Recognized Expert Expert
        • Apr 2006
        • 8834

        #4
        1. Open the Report in Design View
        2. View ==> Code
        3. Insert ==> Procedure
          1. Name = LabelSetup
          2. Type = Function
          3. Source = Private
        4. Type or Copy-N-Paste the Code between:
          Code:
          Function LabelSetup()
            'code goes here...
          End Function

        Comment

        • teresedp
          New Member
          • Dec 2010
          • 3

          #5
          I tried that and it didn't work. But hadn't I already declared it in the original code snippet I posted?
          Code:
           '*********************************************************
              'Declarations section of the module.
             '**********************************************************
            
            Option Compare Database
            Option Explicit
            
            Dim LabelBlanks&
            Dim LabelCopies&
            Dim BlankCount&
            Dim CopyCount&
             
            '==========================================================
              ' The following function will cause an input box to
              ' display when the report is run that prompts the user
              ' for the number of used labels to skip and how many
              ' copies of each label should be printed.
           '==========================================================
            
            Function LabelSetup ()
               LabelBlanks& = Val(InputBox$("Enter Number of blank  
                    labels to skip"))
               LabelCopies& = Val(InputBox$("Enter Number of 
                    Copies to Print"))
               If LabelBlanks& < 0 Then LabelBlanks& = 0
               If LabelCopies& < 1 Then LabelCopies& = 1
            End Function
          Other than the function now saying "Private" before it, it looks no different.

          teresedp

          Comment

          • ADezii
            Recognized Expert Expert
            • Apr 2006
            • 8834

            #6
            This is only the Function Declaration, where is the remainder of the Code?

            Comment

            Working...