Results 1 to 7 of 7
  1. #1
    Join Date
    May 2006
    Posts
    178

    Unanswered: problem with calling a function in a module or class?

    i have tried a code that i found on here to allow me to make enable/disable subform allowedits/deletions and additions. here it is

    Code:
    Sub FSubAllow_Individual(strFormName As String, blnAllow As Boolean)
        Dim ctrl As Control
    
        Set ctrl = Me.Controls(strFormName)
        ctrl.Form.AllowEdits = blnAllow
        ctrl.Form.AllowAdditions = blnAllow
        ctrl.Form.AllowDeletions = blnAllow
    End Sub
    When i call it like this
    Code:
    FSubAllowIndividual "fsub1", True
    FSubAllowIndividual "fsub2", True
    FSubAllowIndividual "fsub3", True
    i get this error msg "Compile error: Invalid use of Me keyword"

    when i clicked on help it is saying that the "me" keyword appeared in a standard module, but when i put it in the class module i get another error saying that "comile error: sub or function not defined"

    can someone please help

  2. #2
    Join Date
    Nov 2007
    Location
    Adelaide, South Australia
    Posts
    4,049
    I think you need to put the first code in the form's code module, not one in the modules section of your database... it's not designed to do anything more than enable/disable subforms... I think. I know that you cannot use Me. in any module other than a form or report module and that top code segment does.

    You can either try putting the code in your form's code module or modify the sub to be form independent.
    Owner and Manager of
    CypherBYTE, Microsoft Access Development Specialists.
    Microsoft Access MCP.
    And all around nice guy!


    "Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
    "...teach a man to code and he'll be frustrated for life! " -- georgev

  3. #3
    Join Date
    May 2006
    Posts
    178
    Thanks Trekker ill give it ago.. you always come to my rescue. Thanks!
    aboo

  4. #4
    Join Date
    May 2006
    Posts
    178
    Hey trekky,

    Worked a treat! thanks

  5. #5
    Join Date
    Nov 2007
    Location
    Adelaide, South Australia
    Posts
    4,049
    You're most welcome
    Owner and Manager of
    CypherBYTE, Microsoft Access Development Specialists.
    Microsoft Access MCP.
    And all around nice guy!


    "Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
    "...teach a man to code and he'll be frustrated for life! " -- georgev

  6. #6
    Join Date
    Dec 2004
    Location
    Madison, WI
    Posts
    3,926
    Another way is to use Forms!MyFormName versus me in the function itself. I usually prefer this way to keep additional code out of the forms.
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

  7. #7
    Join Date
    Nov 2007
    Location
    Adelaide, South Australia
    Posts
    4,049
    I hate doing that. I like all the things done in modules to be form independant -- no direct references to a form.

    I either pass the name of the form to the function or I use ActiveForm.
    Owner and Manager of
    CypherBYTE, Microsoft Access Development Specialists.
    Microsoft Access MCP.
    And all around nice guy!


    "Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
    "...teach a man to code and he'll be frustrated for life! " -- georgev

Posting Permissions

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