Results 1 to 9 of 9

Thread: Access Modules

  1. #1
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Cornwall, England
    Posts
    393
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Access Modules

    I have two forms - MainForm and SearchForm. The MainForm has a number of controls and two subforms. 1 control is a combo box and another is a command button that linkls to the SearchForm. On the SearchForm there is a command button to return to the MainForm, hopefully with a record to display. What i am trying to do is get the MainForm combobox_afterupdate code to run but i do not know how to reference it as it is in the MainForm Class Module and the commandbutton that is being clicked is in the SearchForm Class Module. What syntax do i need please ?

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

    Re: Access Modules

    The cleanest approach would be to put the code into its own Public sub in the Main Form and call that routine from your combobox AfterUpdate event procedure. Since the sub is now public, you can also call it from the other form, although you will have to reference it as a method of its parent form.
    Charlotte

  3. #3
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    The Netherlands
    Posts
    216
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Access Modules

    I agree completely with Charlotte.

    Program a public function in a public module. You can call that function directly from the afterupdate event in the properties window of any control you want. You call it like this: =fnMyFunctionName()
    Note the '=' sign!

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

    Re: Access Modules

    Actually, what I was talking about was creating a public routine in the code behind the Main Form. If you declare a routine as public in a class module, including the module behind a form, you can call it from outside the object. Doing it that way allows you to use the built-in Me object and to reference the controls on the form in question within the code routine rather than having to pass them to an outside routine.
    Charlotte

  5. #5
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Cornwall, England
    Posts
    393
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Access Modules

    OK, come on now!! Which one is best ?[img]/w3timages/icons/hairy.gif[/img]

  6. #6
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: Access Modules

    They'll both work but IMHO Charlotte's method is easier to work with for the reason she mentioned - i.e. you can use Me rather than having to use eg Forms!formname
    I guess that's a matter of personal taste though.
    Regards,
    Rory

    Microsoft MVP - Excel

  7. #7
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    The Netherlands
    Posts
    216
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Access Modules

    There is an advantage putting the code in a module.
    If you don't have any code at all in the module attached to a form, you can set the HasModule property of that form to False. The form then does not have a module anymore resulting in a quicker load of the form.
    If you load a form it's module is loaded too, if the form doesn't have a module that part isn't carried out anymore.

    Bart

  8. #8
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: Access Modules

    That's a good point, though I couldn't say I've ever had a really noticeable performance hit from having a module (maybe my stuff's just not complicated enough??) All I meant was that I personally find Charlotte's method easier to work with - I wouldn't claim to be an expert by any means.
    Regards,
    Rory

    Microsoft MVP - Excel

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

    Re: Access Modules

    IMHO the whole concept of "light" forms is intriguing as a concept but is irrelevant in virtually all applications. I've created them, and I have standard code that is called by all my forms. And I often control my form events from outside classes.

    However, when you need to call a particular kind of function that applies to a particular condition in one particular form, it makes more sense to use the class module behind the form.
    Charlotte

Posting Permissions

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