If Then statement VBA

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a form for keeping track of company assets (Computers, Cell Phones,
Fax Machines...). I have a combo box (Asset Type) where you can select the
type of asset that you will be entering information about. I have a combo box
(Hard Drive Size) with visible set to false. I only want this combo box to
become visible if the selection in "Asset Type" is "Computer". Can someone
give me an example IF statement to use with my form?
 
Bexar,
In order to show/notshow your combo, you'll need code in 2 places... on
the AfterUpdate event of AssetType, and on the OnCurrent event of the form
itself.

Private Sub AssetType_AfterUpdate()
If AssetType = "Computer" Then
HardDriveSize.Visible=True
Else
HardDriveSize.Visible=False
End if
End Sub

Use the same code in the form OnCurrent Event to show/notshow the combo
when browsing bewteen records.
hth
Al Camp
 
No need for an IF statement. Use the AfterUpdate event of the Asset Type
combo box to make the other combo box visible or invisible:

Private Sub Asset_Type_AfterUpdate()
Me.[Hard Drive Size].Visible = (Me.[Asset Type].Value = "Computer")
End Sub
 
Thank you, it worked perfectly. But now i have another problem. There are
several controls and instances. I'm using tab controls for the assets now
instead of individual combo boxes. When i select "Cell Phone" from the "Asset
Type" box i want the "Cell_Info" tab to display. It works fine for my current
tab (Computer_Info) but i'm at a loss as to adding more "if then" statements
for all possible selections.

One last thing. I was told by another user that the style of tab control can
be changed to "none". I've been unable to find this option anywhere in the
tab control properties. Any advice?
 
Bexar,
If you're going to take several different actions, according to the value
of AssetType, then check out "SelectCase" in Help.
That should be easier to build and maintain than multiple If statements with
multiple actions.
hth
Al Camp
 
Back
Top