Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Conditional selection of fields on a form

Status
Not open for further replies.

vakjay

Technical User
Jan 29, 2004
7
AU
I am using a multi tabbed form. All the tabs are in the details section. These are few text boxes (displaying fields) in the Header section of the form. I want to display these objects only when some of the tabs are selected. They should not be shown when any of the other tabs are selected.

Can some one please help me to get it done.
 
How are ya vakjay . . . . .

Control the Visible property of the Textboxes with the GotFocus events of the other controls.

TheAceMan [wiggle]

 
Have you tried using the tab's ClickEvent to make the text box's visible and invisible? Also the form's On Load event you can set the box's visible if the first tab is the one should not allow the text box to be shown.

ProDev, MS Access Applications
Visit me at ==> Contact me at ==>lonniejohnson@prodev.us

May God bless you beyond your imagination!!!
 
Hi Lonnie,

Thanks very much for your reply. I tried the Click event of tabs. Unfortunately, the code was not run when the particular tab was clicked. I just used a MsgBox to check whether the code is run.
This is how I did it. In the design view, I clicked right mouse button on the selected tab (which is named "Setup"). Then in the properties of the "Setup" page, I selected [Event procedure] for "On Click" event. Then I wrote the following code.

Private Sub Setup_Click()
MsgBox "Setup Selected"
End Sub

Next, I started the application and clicked on the "Setup" tab. I did not get the Message box. Have I done something wrong.
 
Dear TheAceMan1,

Thanks for your reply. I am very new to Access Programming. Could you please explain a bit more. A small example would help me a lot.

Thanks again.

 
vakjay! . . . . .

Hang in there . . . Have a meeting this mourning thats gonna take a couple of hours.

Look for a post around 11ist . . . .

TheAceMan [wiggle]

 
OK . . .vakjay . . . here we go . . .

To solve your problem you need to use some event from the Tab Control to manipulate your textboxes of interest. Lonnie had the right idea in relation to the Click Event, but I myself have never gotton it to work. An event that always works and tracks Page changes in the Tab Control, is the Change Event. Any time you select a different page (tab) in the control, the Change Event is triggered. This event will be used to handle your textboxes.

For your textboxes, you'll be controling the Visible Property of each. This property hides or shows the textbox.

As an example, lets say we have a Tab Control named "TC1" with five pages. And we want to hide the textboxes when the 3rd or 4th tabs are selected. The following code would be placed in the Change Event for the Tab Control to accomplish this:

Dim TB As TabControl

Set TB = Me!TC1

If TB.Value = 2 Or TB.Value = 3 Then
Me!txt1.Visible = False
Me!txt2.Visible = False
Else
Me!txt1.Visible = True
Me!txt2.Visible = True
End If

Note that the values in the code are 2 & 3 instead of 3 & 4. This is because the tabindex for the control is zero based (starts at zero), so 1 has to be subtracted from the actual position.

Events play a major role in any application interface you may design. So get to know them well.

TheAceMan [wiggle]

 
Thanks TheAceMan, "TabControl Change" did the job. Not only that, I was able to fix some other problemsn as well. Previously, these was some code behind those tab click event procedures which have never worked. Now I moved them to TabControl Change and they all started working OK. Thanks for your tip. Your code example helped me to do it very easily.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top