Make a sub form visible with a combo box selection

E

Eric

I have a form (frmBids) that has a combo box (cboContractType) that
pulls two values from table (domContractType): Column 1 - ID; Column 2
- Name. The bound column is Column 1 (hidden in the combo box) and it
stores the numeric values into tblBids!ContractType. I am using the
combo box selection to make visible a sub-form (sbfBidSubs) located on
a tabbed page (tabBids) further down the form. I set the visible
property on the sub-form to be No by default. I then set the
AfterUpdate properties to make visible the sub-form when the user
selects option 2 (Sub) in the combo box, but not when selecting option
1 (Prime).

Private Sub cboContractType_AfterUpdate()
If Me!cboContractType = 2 Then sbfBidSubs.Visible = True Else
If Me!cboContractType = 1 Then sbfBidSubs.Visible = False
Me!sbfBidSubs.Requery
End Sub

If I am adding a new record, the combo box / sub form display function
works just fine.

The problem arises if I go back into modify a record. If an existing
record has 'Sub' selected in the combo box already, the sub form does
not display. I have to go and select it again from the combo box
before the sub form will display. I would like the sub form to check
automatically if 'Sub' is selected in the combo box and display
without me having to do anything on existing records.

The other problem, which I believe to be related is that the sub form
remains displayed on the new record if I try to add a new record after
viewing an existing record and re-selecting 'Sub' from the combo box
to make the sub form visible on that existing record.

Any thoughts on how I can get this to display correctly?
 
B

Beetle

I have a form (frmBids) that has a combo box (cboContractType) that
pulls two values from table (domContractType): Column 1 - ID; Column 2
- Name. The bound column is Column 1 (hidden in the combo box) and it
stores the numeric values into tblBids!ContractType. I am using the
combo box selection to make visible a sub-form (sbfBidSubs) located on
a tabbed page (tabBids) further down the form. I set the visible
property on the sub-form to be No by default. I then set the
AfterUpdate properties to make visible the sub-form when the user
selects option 2 (Sub) in the combo box, but not when selecting option
1 (Prime).

Private Sub cboContractType_AfterUpdate()
If Me!cboContractType = 2 Then sbfBidSubs.Visible = True Else
If Me!cboContractType = 1 Then sbfBidSubs.Visible = False
Me!sbfBidSubs.Requery
End Sub

If I am adding a new record, the combo box / sub form display function
works just fine.

The problem arises if I go back into modify a record. If an existing
record has 'Sub' selected in the combo box already, the sub form does
not display. I have to go and select it again from the combo box
before the sub form will display. I would like the sub form to check
automatically if 'Sub' is selected in the combo box and display
without me having to do anything on existing records.

The other problem, which I believe to be related is that the sub form
remains displayed on the new record if I try to add a new record after
viewing an existing record and re-selecting 'Sub' from the combo box
to make the sub form visible on that existing record.

Any thoughts on how I can get this to display correctly?

Try moving the code to your forms OnCurrent event rather than your
combo boxes AfterUpdate event.

HTH
 
E

Eric

Try moving the code to your forms OnCurrent event rather than your
combo boxes AfterUpdate event.

HTH

That solved the problem with the sub form not showing up on an
existing record. The sub form still remains visible if go to add a
new record after viewing an existing record using the record selector
button at the bottom |>*| though.
 
U

UpRider

Eric, add this code in the form's current event:
if me.newrecord then
subform.visible = false
endif

You already have some code in that event, so you may have to figure out how
to integrate this into the big picture there.

UpRider
 
E

Eric

Eric, add this code in the form's current event:
if me.newrecord then
subform.visible = false
endif

You already have some code in that event, so you may have to figure out how
to integrate this into the big picture there.

UpRider

Fantastic!! That worked exactly like I wanted it to. Thank you so
much.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top