Results 1 to 4 of 4
  1. #1
    kattatonic1 is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2013
    Location
    Toronto, Canada
    Posts
    77

    How to use same code for a field on every form it appears

    Hello,



    I have a field called dblActivePositionNumber. On one form if you double-click someone's number, I have it open the relevant Position form to that record. The users love that and have already requested the functionality in another place. I would like to make this a standard. Is that possible by storing the code in a particular place or in a particular way? I.e., Anywhere dblActivePositionNumber is displayed, you can double-click it and launch the position form/correct record. Or do I really have to repeat the code on every single form?

    Thanks for thoughts,

    Kay

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,619
    The double-click event can call a procedure that is in a general module. The procedure can have arguments for the Position form and record ID.

    If the procedure is a Function, then the event property can directly call the function without even creating the double-click event VBA procedure.

    Calling the procedure would be:

    OpenPositionForm("formname", ID)

    The procedure would be like:

    Sub OpenPositionForm(strForm, intID)
    DoCmd.OpenForm strForm, , , "ID=" & intID
    End Sub


    What do you mean 'relevant Position form'? Isn't there only one Position form?

    How many forms is dblActivePositionNumber used on?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    kattatonic1 is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2013
    Location
    Toronto, Canada
    Posts
    77
    Hi June7,

    Re "relevant", yes -- there is only one position form I want to pop up for this functionality; that would not vary.

    dblActivePositionNumber probably shows up on about 15-20 different forms.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,619
    Then the strForm argument is not needed.

    Make the procedure a function and call it from the event property with:

    =OpenPositionForm(ID)

    Use appropriate field name in place of ID, which I guess is dblActivePositionNumber.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Replies: 16
    Last Post: 12-12-2013, 01:23 PM
  2. Replies: 3
    Last Post: 09-08-2011, 04:40 PM
  3. report the # of times a name appears in a field
    By rankhornjp in forum Reports
    Replies: 25
    Last Post: 08-04-2011, 01:45 PM
  4. Replies: 4
    Last Post: 09-10-2009, 03:09 AM
  5. Replies: 1
    Last Post: 08-27-2008, 12:39 AM

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