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

Making a combo Visible dependant upon another Combo 3

Status
Not open for further replies.

MrPiccolo

Technical User
Mar 29, 2004
15
GB
Hi Guys,
I have a subform that has 2 combo boxes on it;
I want to be able to make the second combo box visible AND active when the first cbo has a value of 1.
The before update event for the first cbo looks like the following;
Private Sub RadiationRecorded_BeforeUpdate(Cancel As Integer)

If Me![RadiationRecorded] = 1 Then
Me![Radiation].Visible = -1
Else
Me![Radiation].Visible = 0
End If

End Sub
However this sub does not work as it generates a "property not possible" type of message when the second cbo is selected!
What am I doing wrong please?
PS How do I refresh the form before I open it (in order to "hide" the dependant cbo of a new record)?
Many Thanks.

 
If Me![RadiationRecorded] = 1 Then
Me![Radiation].Visible = True
Else
Me![Radiation].Visible = False
End If


Hth
Bill
 
Oh also it should go in the After_Update event not the before_update of the RadiationRecorded Combo Box. As far as when a form opens you can have the same if statement in the on_current event of the form. This way the only way it is visible is if readiationrecorded has the value 1

Bill
 
Even though you have a subform, it is still referenced through the main form. Try this for referencing:

If Forms!nameofmainform!subformname.Form![RadiationRecorded] = 1 Then
Forms!nameofmainform!subformname.Form![Radiation].Visible = True
Else
Forms!nameofmainform!subformname.Form![Radiation].Visible = False
End If


HTH


Regards
Rod
 
Oops didnt see the subform part of that or else I would have said the same lol

Glad you caught that Rod.

Bill
 
Thanks Bill,
However still got 2 problems!
1) The second cbo doesn't hide if the first cbo is changed back to 0 (instead of 1).
2) There are 6 pairs of linked cbo's on this subform; how do I hide all (6) dependant boxes using the on_current event line of the subform?
MrPiccolo

 
1. Can you post the code your using for problem #1
2. Are these 6 pairs the linked the same as the the first set you talked about?

Bill
 
I believe that you should put the code in the sub form. The code should look something like this:

If Me.cmbRadiationRecorded = 1 Then
Me.cmbRadiationRecorded.SetFocus
Me.cmbRadiation.Visible = False
Else
Me.cmbRadiation.Visible = True
End If
You can enter this in the cmbRadiationRecord After Update Event and in the Forms On Current Event (the sub form). Those events are going to fire when you change the value of the combo box and when you move to a new record in the main form.

Also, it is good practice to name your controls something other than the Bound Field name when ever you are going to be using them in code. (ie. cmbRadiationRecord vs. RadiationRecord)


Hope this helps.

OnTheFly
 
Hi Guys, we’re nearly there! Thanks for all your hard work. Bill, here are the main subroutines I have for my mainform and subform in my database that records data on Patients presenting to hospital with Abdominal Pain. Please see my question at the end of the code listings:

“Frm_visits” (mainform) has a Command Button to Open the Sub-form “PAIN”:

Private Sub Command12_Click()
On Error GoTo Err_Command12_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "Pain"

stLinkCriteria = "[VisitID] = Forms![Visits]![VisitID]"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_Command12_Click:
Exit Sub

Err_Command12_Click:
MsgBox Err.Description
Resume Exit_Command12_Click

On Opening the Subform “Pain” the OnCurrent Event line is:

Private Sub Form_Current()

If Me![DurationPainRecorded] = 1 Then
Me![DurationPainRecorded].SetFocus
Me.[DurationPain].Visible = True
Else
Me![DurationPain].Visible = False
End If

End Sub

(This makes visible (or not) the ComboBox [DurationPain], depending on the value of the ComboBox [DurationPainRecorded]) :–
However this subroutine only checks theses 2 “linked” combo-boxes; there are also 5 other similarly linked Combo boxes that need to be “refreshed” in the same way when the subform “Pain” is opened. Can this be done simultaneously when the subform is opened? Eg. As mentioned before another 2 pairs of linked Comboboxes are [RadiationRecorded] and [Radiation];

Private Sub RadiationRecorded_AfterUpdate()
If Me.RadiationRecorded = 1 Then
Me.RadiationRecorded.SetFocus
Me.Radiation.Visible = True
Else
Me.Radiation.Visible = False
End If
End Sub

Is it possible to check all such linked comboboxes in the OnCurrent event line as well as the first 2 comboboxes mentioned above??
MrPiccolo.
 
Yes, you should be able to put the code for all pairs in on Current or you can just fire those events from the OnCurrent

ie.
Sub Form_Current()
RadiationRecorded_AfterUpdate
DurationPainRecorded_AfterUpdate
....

Just an FYI, when you refered to the Form with the combo boxes as a Sub Form we were assuming that it was imbedded in a main form. Thus the confusion on the first couple of posts.

Hope this helps.

OnTheFly
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top