Wrox Programmer Forums
|
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 28th, 2004, 10:59 PM
Registered User
 
Join Date: Jun 2004
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default combo box

Hi Group

I have a form with a subform on it. Is it possible to have a combo box that would limit subform to its selection ?

 
Old June 29th, 2004, 03:38 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
Send a message via ICQ to SerranoG Send a message via AIM to SerranoG
Default

Yes, you would code the combobox's AFTER UPDATE event to change the subform's source object property using an SQL statement that varies based on your selection. For example:

Code:
Select Case Me.cboMyCombobox
   Case "This"
      Me.sfrMySubform.SourceObject = "Select ..."
   Case "That"
      Me.sfrMySubform.SourceObject = "Select Something else..."
   Case Else
      Me.sfrMySubform.SourceObject = "Select Different..."
End Select
Where the actual "Select ..." would be a REAL statement instead of these fake ones, or they would be names of valid tables or queries.




Greg Serrano
Michigan Dept. of Environmental Quality, Air Quality Division
 
Old June 30th, 2004, 09:14 AM
Registered User
 
Join Date: Jun 2004
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi SerranoG
doesn't work; the combo box now shows only distinct records that are in a column. (1,2,4)
I need to specify which column of the subform should equal that selection
i am trying

Private Sub cmbFrm1_AfterUpdate()
    Me.FormQuery1.SourceObject = "'Select * From FormQuery1 Where AppsID =' & cmbFrm1.text & '"'
End Sub


 
Old June 30th, 2004, 10:47 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
Send a message via ICQ to SerranoG Send a message via AIM to SerranoG
Default

No, your select statement is not correct. You have

Me.FormQuery1.SourceObject = "'Select * From FormQuery1 Where AppsID =' & cmbFrm1.text & '"'

Me.FormQuery1 is the name of your subform, correct? How can you SELECT FROM FormQuery1? You cannot select from a form, you have to select from a table or query. What's the name of your table or query?

Me.FormQuery1.SourceObject = "Select * From {your table or query name here} Where AppsID = '" & Me.cmbFrm1 & "'"

Also, note the use of " and '. You have them backwards.


Greg Serrano
Michigan Dept. of Environmental Quality, Air Quality Division
 
Old June 30th, 2004, 11:05 AM
Registered User
 
Join Date: Jun 2004
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

No, still doesn't work; actually i decided to make it simpler. Instead of subform i put list.
so now i assume it should be something like ---

Private Sub cmbFrm1_AfterUpdate()
     lstForm1.Column(0) = cmbFrm1.text
End Sub

still doesn't work though :(


 
Old June 30th, 2004, 11:12 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
Send a message via ICQ to SerranoG Send a message via AIM to SerranoG
Default

I'm sorry, but you're not making any sense to me.

lstForm1.Column(0) = cmbFrm1.text

That statement does not change a subform's source object to match a combobox (your original question). The above statement you wrote is the way to make the the first item of a list box = the current value of a combobox.


Greg Serrano
Michigan Dept. of Environmental Quality, Air Quality Division
 
Old June 30th, 2004, 11:31 AM
Registered User
 
Join Date: Jun 2004
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Serano,

I dicided to use list boxes instead of subforms, so i need the same, only for list boxes. That

Private Sub cmbFrm1_AfterUpdate()
     lstForm1.Column(0) = cmbFrm1
End Sub

doesn't work however
i get 'Object Required' error

 
Old June 30th, 2004, 01:00 PM
Registered User
 
Join Date: Jun 2004
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

actually, i don't seem to be needing all the extra quotes ;
lstForm1.RowSource = "Select * From FormQuery Where AppsID =" & cmbFrm1.Text

works fine






Similar Threads
Thread Thread Starter Forum Replies Last Post
Populate a text box from a combo box value dnf999 Access VBA 7 February 6th, 2012 02:24 PM
Combo box to display items from parent combo box Gini Visual Studio 2008 0 June 18th, 2008 12:30 AM
Count in combo box(display results in text box) mboyisis Access 4 April 4th, 2008 07:08 AM
Combo box choice creating filtered combo box stevensj5 Access 11 September 13th, 2007 11:33 AM
Populate List Box by Combo Box Selection mmcdonal Access 2 June 15th, 2004 12:08 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.