Problems with Making Hidden Fields Visible Based on Values of othe

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

Guest

I am having a problem. I Have a drop down menu of different predefined
values. I want to set it up so that when one value is selected, I havea
series of different fields appear. When you select anothe value, those same
fields dissappear and the fields pertaining to the new value of the drop down
box appear in the same place. I have Five different drop down box values
that I need to set for. I also want to make it so that when I move on to a
new records, the proper fields are displayed depending on what value is
already recorded for that particular drop down box.

I know it is a lot of help I need, I am fairly new to Access. I know how to
make forms, and reports, and quiries and stuff, but I have never done coding
in Access. I know I right click (I'm using Access 2003) and go to "Build
Event" then choose "Build Code" and it brings me to the area to work in, but
things I have tried don't work.
 
1. Open a form in design
2. Right click on a control and select properties
from the menu
3. click the tab "ALL"
4. Look down the left side for Visible, enabled,
and locked. These 3 properties will give you
different results. Play around with them to see
what you get.

In the AfterUpdate event of your comboBox and the OnCurrent
event of the form, you can do something like this.

Me!ControlName.Visible = False
or
Me!ControlName.Visible = True

Me!ControlName.Enabled = False
or
Me!ControlName.Enabled = True

Me!ControlName.Locked = False
or
Me!ControlName.Locked = True

Sample code in AfterUpdate or OnCurrent event:

If Me!ComboBoxName = "SomeValue" then
Me!ControlName.Visible = False
Else
Me!ControlName.Visible = True
EndIF

You can also use a select case statement in the AfterUpdate
or OnCurrent event.


Select Case Me!ComboBoxName
Case "SomeValue1"
Me!ControlName1.Visible = False
Me!ControlName2.Visible = False
Me!ControlName3.Visible = True
Me!ControlName4.Visible = True
Case "SomeValue2"
Me!ControlName1.Visible = True
Me!ControlName2.Visible = True
Me!ControlName3.Visible = False
Me!ControlName4.Visible = False
End Select

You can make the routine a subroutine in the General
Declaration section and just call it form both events.


Sub ChangComboBoxNameRtn( )
If Me!ControlName= "SomeValue" then
Me!ControlName.Visible = False
Else
Me!ControlName.Visible = True
EndIF
End Sub


To Call the routine:

ChangComboBoxNameControlsRtn

HTH

Ron
ps: There is no logic to my code, just examples.
 
Ronald, I know this is a really basic question, but what is "OnCurrent event"
specifically used for? I know that AfterUpdate runs the script of that
particular field anytime it is updated.

Also, how can I ensure that the proper fields are being displayed when I go
from record to record when viewing my form?
 
I am having a problem. I Have a drop down menu of different predefined
values. I want to set it up so that when one value is selected, I havea
series of different fields appear. When you select anothe value, those same
fields dissappear and the fields pertaining to the new value of the drop down
box appear in the same place. I have Five different drop down box values
that I need to set for. I also want to make it so that when I move on to a
new records, the proper fields are displayed depending on what value is
already recorded for that particular drop down box.

I know it is a lot of help I need, I am fairly new to Access. I know how to
make forms, and reports, and quiries and stuff, but I have never done coding
in Access. I know I right click (I'm using Access 2003) and go to "Build
Event" then choose "Build Code" and it brings me to the area to work in, but
things I have tried don't work.

In Design view, right click on the combo box.
Click on the Event tab.
On the After Update line write
[Event Procedure]
Click on the little button with the 3 dots that appears on that line.
When the Code window opens, the cursor will be flashing between 2
already existing lines of code.
Between those 2 lines write:

If Me![comboName] = Value1 Then
[ControlA].Visible = True
[ControlB].Visible = True
[ControlC].Visible = False
[ControlD].Visible = False
[ControlE].Visible = False
[ControlF].Visible = False
ElseIf Me![ComboName] = Value2 Then
[ControlA].Visible = False
[ControlB].Visible = False
[ControlC].Visible = True
[ControlD].Visible = True
[ControlE].Visible = False
[ControlF].Visible = False
Else
[ControlA].Visible = False
[ControlB].Visible = False
[ControlC].Visible = False
[ControlD].Visible = False
[ControlE].Visible = True
[ControlF].Visible = True
End if

I've only given 3 Values, just add 2 more ElseIf's as needed.
Substitute your actual control names in the above.

Then place the same code in the form's Current event.
 
The Current event occurs when the focus moves to a record, making it the
current record, or when the form is refreshed or requeried.

From the Help file.


Ron
 
Back
Top