Results 1 to 5 of 5
  1. #1
    eww is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Aug 2010
    Posts
    125

    Consolidating Code


    I've got basically a self built navigation panel consisting of several buttons. This navigation panel is consistent throughout all of the main forms, and presently the approach I've taken is to just copy the code that it runs off of throughout all the forms.

    I know there has to be a more effecient way of coding this, but I'm a little bit confused with how Class modules/regular modules vs. form modules work. Is there a public function or procedure I could write that would store this code once and then I could call it whenever the buttons were clicked with a simple line of code?

    Before I posted this I tried to stick this in a Module and declare it as a Public sub to be referenced on the control click. I think part of my problem though is that the code references controls on the form. I'm not sure how to handle this in the Module, besides maybe changing

    Me.btnCPByJobNum.Visible = True

    to

    Forms.variable.btnCPByJobNum.Visible = True

    and then in the procedure on the form declaring the variable and setting it to the form name. I'm just guessing right now though.

  2. #2
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    As you suspect, you can't use "Me" in a standard module. You could have the module accept the form name as an input parameter, and then I think the syntax would be:

    Forms(variable).btnCPByJobNum.Visible = True
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    eww is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Aug 2010
    Posts
    125
    Okay, so say I have a button on the Home page, but I want to store for it in the module (because it is the same button as on other forms). Would this be the proper way to do things?

    On frmHome:
    Private Sub btnCPALLProj_Click()
    Set vForm = frmHome
    Call AllProj (I don't remember if this is the correct syntax)
    End Sub

    On Module:
    Public Sub AllProj()
    Forms(vForm).btnCPByJobNum.Visible = True
    End Sub

  4. #4
    eww is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Aug 2010
    Posts
    125
    Just tried it and it seems to be working great. Thanks Paul.

  5. #5
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Happy to help Eric.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Code to add Yes and N/A's
    By Brian62 in forum Queries
    Replies: 1
    Last Post: 11-30-2010, 05:16 PM
  2. Word code in Access - How to modify my current code
    By Alexandre Cote in forum Programming
    Replies: 0
    Last Post: 11-15-2010, 08:26 AM
  3. Code in combobox, code in text box
    By float in forum Forms
    Replies: 3
    Last Post: 09-29-2010, 07:12 AM
  4. Access 2003 code vs Access 2007 Code
    By ralphjramirez in forum Access
    Replies: 5
    Last Post: 11-23-2009, 12:33 PM
  5. Need help with code
    By hoenheim in forum Programming
    Replies: 9
    Last Post: 09-11-2008, 04:19 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums