Solved

How to Change Combobox Recordset Source

Posted on 2004-04-25
6
697 Views
Last Modified: 2010-08-05

I'm using the Recordset property off a combobox to populate the combobox from an ADO recordset.  I do this for a lot of my quasi-static lookup lists by saving persistent ADO recordset files on the front ends of the data base.   It works well, except for when I try to change the recordset and then re-set the combobox Recordset property.  (Simple example:  change a State lookup list from the 51 USA states to the 13 Canadian provinces/territories based on a country selection).  The combobox doesn't seem to "take" the new values of the changed recordset.  Its dropdown list either displays all blanks or simply displays the orginal recordset values.

I've tried to use ADO methods (like .Delete, .AddNew and .Update) directly on the combobox recordset object.  I've also tried to first set the combobox recordset object to Nothing, and then set a new/changed recordset to the combobox recordset object.  Neither seems to do the trick, nor other variations.

Any ideas?  

Thanks,
Wyatt

0
Comment
Question by:WyattRidesAgain
6 Comments
 
LVL 11

Expert Comment

by:Mighty_Silly
Comment Utility
What is the code you use for "changing" the combo box's recordsource?

-Silly-
0
 
LVL 119

Expert Comment

by:Rey Obrero
Comment Utility
You don't use recordsource property bu the RowSource

Private Sub Form_Load()

Me.Combobox.RowSource= "Select fieldname From Table"
0
 
LVL 54

Expert Comment

by:nico5038
Comment Utility
Did you issue a me.requery to get a fresh form ?

Nic;o)
0
Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
LVL 119

Expert Comment

by:Rey Obrero
Comment Utility
If you want to change RowSource on command button click

Private Sub commandChange_Click()
Me.ComboBox.RowSource=""         'Clears Row SOurce
Me.ComboBox=""                          'Clears box display
Me.ComboBox.RowSource=Select Fieldnames Form Table"




End Sub
0
 
LVL 119

Accepted Solution

by:
Rey Obrero earned 250 total points
Comment Utility
<(Simple example:  change a State lookup list from the 51 USA states to the 13 Canadian provinces/territories based on a country selection).>

Here is how to do this;

Private Sub Form_Load()
Me.cboCountry = ""
Me.cboCountry.RowSource = "Select Distinct Country From TableName"
End Sub

Private Sub cboCountry_AfterUpdate()
Me.cboState=""
Me.cboState.RowSource = "Select Distinct State From TableName " & _
                        "Where [Country]= " & Chr(34) & Me.cboCountry & Chr(34) & " "
End Sub
0
 

Author Comment

by:WyattRidesAgain
Comment Utility
I'm sorry for not responding:  I've been pulled away on some emergency work.  Unfortunately I can't chase this further right now, and may have to re-post the question later.  Let me give out the points so you're not left dangling.  From the quantity of info provided, it seems fair to give capricorn the points.

Thanks for the fast answers!  Sorry we can't conclude this at this point.

Regards,
Wyatt
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
It took me quite some time to sort out all the different properties of combo and list boxes available from Visual Basic at run-time. Not that the documentation is lacking: the help pages are quite thorough and well written. The problem was rather wh…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now