Showing/Hiding a controls on another form by using input variable names

I am trying to build a progress meter (using a pop up form)
I would like to be able to call this form and set certain things when it comes up;
Text of what is happening
% completion
Show the various rectangles as the actual "meter" (there are 10 boxes lined up)

I can change the text values, but am having trouble SHOWING THE RECTANGLES with variable names.

How can I show the various rectangles using an input value for their names?

Code below (of course this is just a simple version for trial purposes):
1. Button on main form; press to start progress meter
2. Progress meter module (showing which text works, and which doesn't

Private Sub Command0_Click()
'this is a button clicked on the "main" form that will initiate the Progress Meter form; it sends the differnt values as shown.
ProgInitiate "master caption text here", "general caption text here",   "caption text here", 2, 44    
End Sub

'below is the modules that shows the Progress Meter form and uses the inputs to set the values

Public Sub ProgInitiate(MasterCaption As String, GeneralCaption As String, Caption As String, ProgBoxNum As Integer, Percent As Integer)
    DoCmd.OpenForm "frmProgressBarForm", acNormal, , , , acWindowNormal 'open progress bar form
    Forms!frmProgBar.SetFocus 'set the focus to the Progress Bar Form
    Forms!frmProgressBarForm.Caption = MasterCaption 			'set caption of the form
    Forms!frmProgressBarForm.lblUpdatingData.Caption = GeneralCaption 	'set the main caption on the form
    Forms!frmProgressBarForm.lbl_StatusText.Caption = Caption  		'caption for each operation that is performed
    'show and set the text box showing the percentage of completion
    Forms!frmProgressBarForm.ProgLevelLabel.Visible = True      	'show the text box show the % of completion
    Forms!frmProgressBarForm.ProgLevelLabel.Caption = Percent & "%" 	'set the value of the percentage of completion

    Dim BoxNumber As Control
'the line below WORKS: there are 10 boxes (ProgBox1, ProgBox2, ProgBox3, etc.)
    Set BoxNumber = Forms!frmProgressBarForm.ProgBox2

'the lines below do NOT work
'but I want to be able to have the box number be an input variable:
'ProgBoxVARIABLE.visible, where VARIABLE is 1-10

dim BoxNumber as string
	BoxNumber = "ProgBox" & ProgBoxNum	'this combines the text with the variable input number

    Forms!frmProgressBarForm.Form!BoxNumber.Visible = True

End sub

Open in new window

Who is Participating?
JezWaltersConnect With a Mentor Commented:
This should show you the general idea for using the Microsoft ProgressBar Control:
Rey Obrero (Capricorn1)Commented:
SheaJeffAuthor Commented:
Thanks for the link; this database is a lot more complicated than I'd like to get, and would take too much time to incorporate and understand.

What I really want to know is simply;

How can I show/hide an object on one form by sending it the object name from another form?
(there are 10 different objects)  
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

If you've got the control name in a variable (say called strControl) then you can make it invisible like this:

    Controls(strControl).Visible = False
Have you tried using the Microsoft ProgressBar control?
Jeffrey CoachmanMIS LiasonCommented:
Basically you need to know ahead of time how many "Things" will happen, then you have to distribute that amount over the 10 bars.

So if 5 things will happen, then is two bars for every one "event"
If 20 things will happen then it is one bar for every two "events"
Make sense...?

So depending on the number of things happening, you may have an issue with "Resolution" with 10 bars.

Jeffrey CoachmanMIS LiasonCommented:
You can also use the Status bar meter:
No offense, but between the status bar progress meter (suggested by capricorn1) and the Microsoft ProgressBar control, you do seem to be somewhat re-inventing the wheel !
Rey Obrero (Capricorn1)Commented:
SheaJeffAuthor Commented:
I like your simple ProgCtrl.  I've never seen this before.
I can get it to work on the main form,
but how do I get it to work on ANOTHER FORM by sending a value (incremented)?
Are you saying that you want the bar to progress based on activity in a different form?
SheaJeffAuthor Commented:

-Click a button on the main form
   - show progress bar form  (always on top)
   - show the rectangle for 10% increment  (ProgBox1)
   - run query1
   - show the rectangle for 20% increment  (ProgBox2)
   - runquery2

I was using 10 different rectangles to indicate the meter; show each box as the increment increases (ProgBox1-ProgBox10).  The 1-10 is the value I want to send to the progress meter module.

I was hoping to stay away from ActiveX as I am not familiar with it and have read that it can cause issues with applications used by different users (like this one)
Jim Dettman (Microsoft MVP/ EE MVE)President / OwnerCommented:
<<Thanks for the link; this database is a lot more complicated than I'd like to get, and would take too much time to incorporate and understand.>>

  Being I was the one that created the sample that he pointed to, cap asked me to drop by.

 Not sure if you really looked at that sample DB or not, but it's about as simple as it gets.  All you need to do is import form frmProgBar into your app, then call it from code like this (which is from frmProgBarDemo):

    Dim pb As New Form_frmProgBar
    Dim intK As Integer

    pb.SetMessage "Message with bar and 5 steps"
    pb.SetCaption "Physical inventory roll"
    pb.SetBarVisible True
    For intK = 20 To 100 Step 20
      pb.SetBarPercent (intK / 100) * 100
      Wait (1)
    Next intK
    pb.SetBarPercent (100)
    pb.SetMessage "Done!"
    Wait (2)
    Set pb = Nothing

Text of what is happening
% completion

  Which is exactly what frmProgBar gives you.

  and if you look at the code in frmProgBar, you'll see that it is doing the progress bar with two overlapping labels.  One forms the background and the other the foregound (which is the bar).

  It would be a small step in the logic to use multiple labels for the foreground and make them visible as needed so you could show seperate rectangles.

  I choose a single bar because it was less overhead and I could vary the width of the bar to anything I choose.

  I don't have time at the moment to whip up an example of that, but I think if you go back and look at the db, then either:

a. it will work for you as is.

b. it works in outline with what you trying to do and would only require modification in the SetBarPercent procedure to show seperate rectangles.

SheaJeffAuthor Commented:
I ended up using this as it was the simplest.  I ended up putting your incrementing of the bar into a module that changes the captions and percentage, the values received from the button click operations.

I was looking at JDettman's solution, but it seemed more complicated for what I wanted.

Now on the button click, I just call:
ProgressFunction  "CAPTION", 90
where the 90 is the increment of your box

The function is roughly:
Public Function ProgressFunction  (Caption As String, ProgBarValue As Integer)
Forms!ProgressForm.lbl_StatusText.Caption = Caption
    Forms!ProgressForm.barProgressBar = ProgBarValue

I'm going to add the incrementing and such so that it doesn't open the form each time, but this will work!
Thanks to all for the help.
SheaJeffAuthor Commented:
Is there a way to change the colour of the "increments" on barProgressBar? barProgressBar
You need to use the Windows API, but yes it's possible to change the bar colour (but it has to be all one colour):
By the way, you can set the .Max and .Min properties to have the bar progress from something other than 0->100 increments.
SheaJeffAuthor Commented:
Perfect on the color!  It even uses the three number type (my company has a specific color and to match it, I need to use this)
Thanks a lot!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.