Results 1 to 5 of 5
  1. #1
    Star Lounger
    Join Date
    Feb 2002
    Location
    Albuquerque, New Mexico, USA
    Posts
    63
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Sub or Function not defined (97)

    I'm getting this message and don't understand why. I have the following routine as the On Open property of my report. I need the value in oldWrkCtr in another routine I'm calling on the detail (On Print) line. This is so straightforward, I don't know what I'm doing wrong.

    Private Sub Report_Open(Cancel As Integer)
    Private oldWrkCtr As Variant
    oldWrkCtr = "000"
    End Sub<font face="Comic Sans MS">text</font face=comic> <img src=/S/help.gif border=0 alt=help width=23 height=15> <img src=/S/frown.gif border=0 alt=frown width=15 height=15>

  2. #2
    4 Star Lounger
    Join Date
    May 2003
    Location
    Austin
    Posts
    401
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Sub or Function not defined (97)

    You're probably going to have to paste the rest of the code to see where it's going wrong...

  3. #3
    Star Lounger
    Join Date
    Feb 2002
    Location
    Albuquerque, New Mexico, USA
    Posts
    63
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Sub or Function not defined (97)

    Thanks, jazman2001 and here it is. The first part just sets colors, fonts, etc. based on a value on the detail line and, if I remove the other code, it works just as it should. The next part (on print) determines the datRevCompDate (if this is a new WrkCtr, use the current date as the starting point; otherwise, use the oldRevCompDate--the one from the previous record.). The last part just sets the oldWrkCtr used in the OnPrint part. It's parts 2&3 that are giving me fits! If I remove the last part, I get another message that my Sub or Function isn't defined and it's on the detail part. HELP!!!
    Attached Files Attached Files

  4. #4
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Scope of Variables (97)

    Your problem is one of scope, which means what parts of the application can see/use the variable and for how long. If you dim a variable within a routine (including the OnOpen event procedure), you can only use that variable within that routine. Its scope is local to the routine.

    If you want to store a value that you can retrieve from another routine, in this case the OnPrint event, you have to declare the variable at a level that will make it available to both the OnOpen and OnPrint events. That means that you have to declare a module level variable, which you do in the declarations section at the head of the module. A variable with a module level scope is available to all routines within the module until the module is closed. In this case, that means until the report is closed.
    Charlotte

  5. #5
    Star Lounger
    Join Date
    Feb 2002
    Location
    Albuquerque, New Mexico, USA
    Posts
    63
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Scope of Variables (97)

    Thank you so much for your help. I finally got things working as I needed. I could not have done this without your help!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •