Using a Command button to Unhide Multiple Controls one at a time

  • Thread starter adurrschmidt via AccessMonster.com
  • Start date
A

adurrschmidt via AccessMonster.com

Access Monster,

I have 5 controls (combo boxes) on a form Each Control is labeled Sample Type
1 through 5 respectively. One is visible the other 4 are not. The combo box
is used enter one of many sample types.

It is possible that for each record there are up to 5 sample types. What I
want to accomplish is the use of one button labeled "Add Sample Type" to
unveil each new Sample Type Control one at a time each time you depress the
"Add Sample Type" button.

I.e. The first time I press the button, sample type 2 becomes visible under
sample type 1. The next time I press the button, sample type 3 becomes
visible under sample type 2....etc....

Is this possible?

Thanks for your time,
Andrew
 
G

Guest

In the Command Button Click Event:

Dim ctls As Controls
Dim intSampleNum As Integer

Set ctls = Me.Controls
For intSampleNum = 1 to 5
If ctls("SampleType" & Cstr(intSampleNum)).Visible = False Then
ctls("SampleType" & Cstr(intSampleNum)).Visible = True
Exit For
End If
Next intSampleNum
set ctls = Nothing
Exit Sub

This will cycle through the controls named SampleType1 through SampleType5
and change the first one it find invisible to be visible. You will also need
a similar routine to make them all invisible except the first one. This
should probably be in the form's Current event:

Dim ctls As Controls
Dim intSampleNum As Integer

Set ctls = Me.Controls
For intSampleNum = 2 to 5
ctls("SampleType" & Cstr(intSampleNum)).Visible = False
Next intSampleNum
set ctls = Nothing

This will have 2 through 5
 
A

adurrschmidt via AccessMonster.com

Thank you Klatuu,

It worked like a charm.
In the Command Button Click Event:

Dim ctls As Controls
Dim intSampleNum As Integer

Set ctls = Me.Controls
For intSampleNum = 1 to 5
If ctls("SampleType" & Cstr(intSampleNum)).Visible = False Then
ctls("SampleType" & Cstr(intSampleNum)).Visible = True
Exit For
End If
Next intSampleNum
set ctls = Nothing
Exit Sub

This will cycle through the controls named SampleType1 through SampleType5
and change the first one it find invisible to be visible. You will also need
a similar routine to make them all invisible except the first one. This
should probably be in the form's Current event:

Dim ctls As Controls
Dim intSampleNum As Integer

Set ctls = Me.Controls
For intSampleNum = 2 to 5
ctls("SampleType" & Cstr(intSampleNum)).Visible = False
Next intSampleNum
set ctls = Nothing

This will have 2 through 5
Access Monster,
[quoted text clipped - 15 lines]
Thanks for your time,
Andrew
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top