Share via

Create a global function

Anonymous
2012-09-14T09:37:10+00:00

Hello

I would like to place some “Help File” buttons around my database.  These will be placed next to buttons, combos, list, forms, etc.  They will allow the user to click the button to see a pop up that will give hints and tips on using that specific control.

At the top of each form I will have a “Show Help” button which will set all the Help Buttons on that form to visible Yes.  This will change to a “Hide Help” caption which will then set the visible to No.

I would like to call a function OnClick of this button

Rather than have this code in each form I would like to create a global module which will set the visible of any buttons named “Help*” on the form that the user is on.  There will be forms and sub forms.

Would it be possible to create such a module? And if so, how would it be done.

The show help button on each form will be called   HelpShowForm1, HelpShowForm2, etc.

This will set the visible of the help buttons on that form eg.  HelpForm1Combo,  HelpFom4NameList, HelpForm27DateOfBirth, etc, etc

Thank you

Microsoft 365 and Office | Access | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

2 answers

Sort by: Most helpful
  1. ScottGem 68,830 Reputation points Volunteer Moderator
    2012-09-14T11:54:40+00:00

    First, I would use a different naming convention. I would use cmdHelpassociatedcontrolThere is noi need to number them that I see. 

    Second, I would set the Tag property of each of those controls to simply Help. So this identifies them as Help buttons.

    Your function would look something like this

    Public Sub ShowHideHelp(frm as Form)

    Dim ctl As Control

    For each ctl in frm.Controls

    If ctl.Tag = "Help"

    If ctl.Visible Then

    ctl.Visible = False

    Else

    ctl.Visible = True

    End If

    End If

    Next ctl

    End Sub

    You would call this sub with the line

    Call ShowHideHelp(Screen.ActiveForm)

    Disclaimer: this code is off the top of my head and untested. It may not be syntactically correct, but should give you the idea.

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2012-09-14T11:40:45+00:00

    You can create a Public Sub in a Standard Module passing in the Form Object (or the Form name and re-create the reference to the Form Object in the Sub). The code in the Sub can traverse the Controls Collection of the Form and for each Control, check whether it is a CommandButton with name starting with "Help" and if so, reverse its visibility.

    If the Control is a SubForm, then make a "recursive" call to the same Sub but this time pass in the Form Object of the SubFormControl.

    Was this answer helpful?

    0 comments No comments