PC Review


Reply
Thread Tools Rate Thread

Change listbox contents based on combobox value

 
 
lecoughlin@gmail.com
Guest
Posts: n/a
 
      14th Nov 2008
I have created a form with a combobox that contains a list all 51
states. I also have a list box that contains all of the states and
their counties. If the user selects "Massachusetts" from the
combobox, I would like the listbox to only show counties in
Massachusetts. How would I go about doing this?

Thanks in advance.
 
Reply With Quote
 
 
 
 
Sean Timmons
Guest
Posts: n/a
 
      14th Nov 2008
Try this

Private Sub State_Name_Change()
Dim strSQL As String
strSQL = "SELECT DISTINCT [CityTable].[City] FROM [CityTable]" & _
"WHERE [State] ='" & Me.[State] & "' ORDER BY [City]"
Me.[City].RowSource = strSQL
End Sub

Assuming state_Name is your combo box name, CityTable is your table with
states and cities.

"(E-Mail Removed)" wrote:

> I have created a form with a combobox that contains a list all 51
> states. I also have a list box that contains all of the states and
> their counties. If the user selects "Massachusetts" from the
> combobox, I would like the listbox to only show counties in
> Massachusetts. How would I go about doing this?
>
> Thanks in advance.
>

 
Reply With Quote
 
lecoughlin@gmail.com
Guest
Posts: n/a
 
      14th Nov 2008
I figured it out. Thanks!
On Nov 14, 4:24*pm, Sean Timmons
<SeanTimm...@discussions.microsoft.com> wrote:
> Try this
>
> Private Sub State_Name_Change()
> Dim strSQL As String
> strSQL = "SELECT DISTINCT [CityTable].[City] FROM [CityTable]" & _
> "WHERE [State] ='" & Me.[State] & "' ORDER BY [City]"
> Me.[City].RowSource = strSQL
> End Sub
>
> Assuming state_Name is your combo box name, CityTable is your table with
> states and cities.
>
> "lecough...@gmail.com" wrote:
> > I have created a form with a combobox that contains a list all 51
> > states. *I also have a list box that contains all of the states and
> > their counties. *If the user selects "Massachusetts" from the
> > combobox, I would like the listbox to only show counties in
> > Massachusetts. *How would I go about doing this?

>
> > Thanks in advance.


 
Reply With Quote
 
Beetle
Guest
Posts: n/a
 
      14th Nov 2008
The row source of your list box should look something like the following;

SELECT CountyName From tblYourTable Where
tblYourTable.State = [cboYourComboBox]

Then, in the After Update event (not the Change event which fires at
*every keystroke*) of your combo box you would requery the list box;

Private Sub cboYourCombo_AfterUpdate()

Me!YourListBox.Requery

End Sub
--
_________

Sean Bailey


"(E-Mail Removed)" wrote:

> I have created a form with a combobox that contains a list all 51
> states. I also have a list box that contains all of the states and
> their counties. If the user selects "Massachusetts" from the
> combobox, I would like the listbox to only show counties in
> Massachusetts. How would I go about doing this?
>
> Thanks in advance.
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Filter a listbox based on the value of a combobox NKK Microsoft Access Form Coding 5 11th Dec 2008 04:45 AM
change combobox values one by one based on selection in multiselect listbox Abdul Microsoft Excel Programming 0 7th Nov 2006 11:55 AM
datagrid, change combobox value at run time based on the value of another combobox at different column zhuang Microsoft Dot NET Framework Forms 0 23rd Feb 2006 05:04 PM
dinamic contents of combobox, listbox etc =?Utf-8?B?WmFwaG9k?= Microsoft Excel Programming 0 30th Dec 2005 11:53 AM
Populating a ListBox Based on the value of a ComboBox =?Utf-8?B?Sm9obiBQaW90cm93c2tp?= Microsoft Access ADP SQL Server 1 2nd Jul 2004 03:27 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:26 AM.