On 21 Jan 2006 19:29:43 -0800, "DSR" <dr*******@hotmail.com> wrote:
Help Please... I would like to populate a combo box on a form with a
query that compares data from two tables. Any record that is unique in
table1 should continue to populate my combobox. The instant the record
appears also in table2 it should no longer be listed in my combo box.
This is not a key field in either of the tables. Basically what I am
trying to do is prevent the user from entering duplicate values even
though it is not a key field. I am trying to do this by limiting their
choices in the combo box. There is a legitimate reason for neither
field being a key.
Thanks for your help
In addition to Jamey's suggestion.
A gotcha you should be aware of, depending on how your design is setup. Filtering a combo in this manner can lead to
existing valid data not being displayed if it no longer meets the criteria of the rowsource SQL/query.
As an example.
I have an existing app with a combo used to define who raised a certain report.
The client requested that the drop down list of the combo include only current employees.
This is easily achieved by adding a criteria to the RowSouce SQL, however it also meant that employees who had left the
company but who had previously raised reports, were no longer being displayed. (The combo appeared blank even though
they had a valid entry)
The way around this is to change the RowSource on entering and exiting the combo -
Sub MyCombo_Enter()
Dim strSQL as String
strSQL = "SELECT EmpNo, EmployeeName FROM tblEmployees WHERE [LeftCompany]=False;
Me.MyCombo.RowSource=strSQL
Me.MyCombo.Requery
End Sub
Sub MyCombo_Exit()
Dim strSQL as String
strSQL = "SELECT EmpNo, EmployeeName FROM tblEmployees;
Me.MyCombo.RowSource=strSQL
Me.MyCombo.Requery
End Sub
Existing data is always displayed correctly as the RowSource returns all records, however new entries (or edits) are
filtered to allow selection of only records which a valid at the time of editing.
This may not apply to your situation, but it is useful to be aware of.
Wayne Gillespie
Gosford NSW Australia