Results 1 to 5 of 5
  1. #1
    New Lounger
    Join Date
    Feb 2001
    Location
    Fort Worth,Tx, USA
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Passing object variables

    I am having a problem passing an object variable to a subroutine. Could you please look at this example and help me understand what's wrong? I am using Access 97 SR2.

    Public Function FirstProcedure()

    Dim MyFrm as Form
    Set MyFrm = Screen.ActiveForm

    'FirstProcedure code

    'Call SecondProcedure
    SecondProcedure(MyFrm)'<Type mismatch error occurs here

    End Function


    Sub SecondProcedure( frm As Form )

    Dim ctl As Control

    For Each ctl In frm.Controls

    'Code for manipulating frm.Controls

    Next ctl

    End Sub


    The examples in help that I can find show using the Me keyword to pass the object to the subroutine. However, I want to place the code in a standard module so that is why I used Screen.ActiveForm.

    The error I get by doing it this way is "Type Mismatch". What's wrong?

    Thanks for your help,

    MorrisK

  2. #2
    Lounger
    Join Date
    Feb 2001
    Location
    TX, USA
    Posts
    34
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Passing object variables

    Exactly which step in your code is breaking? Have you set breakpoints and stepped though it? This will help you answer most of your questions.

  3. #3
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Edmonton, Alberta, Canada
    Posts
    326
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Passing object variables

    I can't answer your specific question, but just an observation; I use Me as a parameter to a global routine quite regularly and have never had a problem. In my case I use it to pass the current report, not the current form, but if it works for reports I'd hazard a guess that it works for forms. (I have a standard global routine for making vertical lines that "stretch" to the full depth of the report section that takes one parameter which is assumed to be a report, and all that I ever pass for that parameter is Me).

    I don't know the guts of Access that well, but my assumption has always been that the keyword Me must occur in form or report code but what Me contains can be passed wherever you want.

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

    Re: Passing object variables

    I suspect your problem is the parens you've wrapped around your argument. You only use parens when you're returning a value from a function or when you call the procedure using the Call keyword. Either this:

    Call SecondProcedure(MyFrm)

    or this:

    SecondProcedure MyFrm

    should work.
    Charlotte

  5. #5
    New Lounger
    Join Date
    Feb 2001
    Location
    Fort Worth,Tx, USA
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Passing object variables

    Thanks Charlotte! Your solution appears to have taken care of the problem. I removed the parentheses and it worked.

Posting Permissions

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