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

Using A Combo box For Subform

Status
Not open for further replies.

Eleventy

Technical User
Aug 12, 2010
17
US
I am attempting to create a Data Entry form (frmDataEntry) where I want to use a combo box (cmbYN) to determine the initial starting point. In this combo box the Row Source is: "";New Customer;Existing Customer.

In the form footer I have some Tabs where the tab in total is:(tabFormFooter), and there are two selectable tabs (tabExistingCustomer), (tabNewCustomer).

Basically I am trying to use VBA code and IF/Then statements to accomplish this. Originally the form footer is invisible and I am using Code int he AfterUpdate event box. The code I am trying to get working just to make the form footer visible is this (and yes I know this is likely not even close but I don't know how to tie events into the combo box selection).

Private Sub cmbYN_AfterUpdate()
If cmbYN = "" Then
FormFooter.Visible = False
If cmbYN = [New Customer] Then
FormFooter.Visible = True
If cmbYN = [Existing Customer] Then
FormFooter.Visible = True
End If
End If
End If
DoCmd.RunCommand acCmdSizeToFitForm
End Sub

I would greatly appreciate any help/ideas. Haha, if not I will just put in buttons.

Thank you.
 
Code:
Private Sub cmbYN_AfterUpdate()
  Me.FormFooter.Visible = Nz(cmbYN, 0)
End Sub
Combo properties
Row Source: 0;"New Customer";-1;"Existing Customer"
Column Count: 2
Bound Column: 1
Column Widths: 0;1"
limit to list: True
 
Would you be willing to kind of expand what I am actually telling Access to do here?

I am reading it as I am declaring that FormFooter.Visible is a function of Nz(CmbYN, 0) with the the Values 0, -1 being tied to New Customer and Existing Customer respectively.

What if I had several items tied to separate tabs in the form footer that I wanted to be able to make them visible based on the selection of the combo box?

I guess I posed kind of a simple question and I am curious if your code can be expanded to more complex situations.
 
Code:
Private Sub cmbYN_AfterUpdate()
  Call showSelected(cmbYN)
End Sub

Public Sub showSelected(intChoice As Integer)
  Dim tb As Access.TabControl
  Dim pg As Access.Page
  Set tb = Me.tbCustomers
  'Assuming you only want to show the selected tab
  'hide all
  For Each pg In tb.Pages
    pg.Visible = False
  Next pg
  'show selected
  tb.Pages(intChoice).Visible = True
End Sub
rowsource: 0;"New Customer";1;"Existing Customer";2;"Something Else
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top