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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to Hide a multiSelect listbox based on the value of another ctl 2

Status
Not open for further replies.

jane30

Programmer
Nov 14, 2000
92
US
Hi,
I have a form bounded to a query, which returns the date and hospital codes.

In the form, there're 3 controls: StartDate, EndDate (both're textbox whose default values are from query) and a multiselect listbox (contains a hospital code list I manually created, not from the query. The reason is I want to include "ALL" in the list).

The scenario is: some users don't need to select a hospital code at all 'cause they don't have other hospitals' data. So, there's no need to show the multiselect listbox for them to select. I plan to create two more hidden textbox (both have control source value from a query), then compare their values. If they're equal, Show the multiselect listbox; not, make it invisible. My question is how? I tried really hard in my code:

Private Sub Form_Load()

If Me!TxtFirstHosp.Value = Me!TxtFirstHosp.Value Then
DoCmd.MoveSize , , , 3090
Else
DoCmd.MoveSize , , , 3990
Me!ListHosp.SetFocus
End If


End Sub

Something wrong with my code??? Please help. Many many thankyous in advance
 
In the OnOpen event of the form place this code (assuming two controls you're comparing txtA and txtB):

If txtA = txtB then
ListBox.Visible = False
Else
ListBox.Visible = True
End if

HTH Joe Miller
joe.miller@flotech.net
 
Unless it is a typo, you are comparing something to itself in your IF statement. You also are not setting the visible property. Something like this:
Code:
Private Sub Form_Load()
 
   If Me!TxtFirstHosp.Value = Me!TxtOtherHosp.Value Then
      DoCmd.MoveSize , , , 3090
      Me!ListHosp.Visible = TRUE
      Me!ListHosp.SetFocus
   Else
      DoCmd.MoveSize , , , 3990
   End If
End Sub
Hope that helps...
Terry M. Hoey
th3856@txmail.sbc.com
While I don't mind e-mail messages, please post all questions in these forums for the benefit of all members.
 
Thank you, Both! I shouldn't overlook that important property.
 
I am having the same problem. Your code is very helpful. How do you pass the hidden control value to the query?

I include the following in my "criteria" grid where txtAppSelected is a hidden text box:

([forms]![key word search]![txtAppSelected]). However the query returns zero records

Thank you.
Jackie
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top