How do I tell if combo value is valid, changing rowsource.

  • Thread starter david epsom dot com dot au
  • Start date
D

david epsom dot com dot au

When I change the rowsource of a combo box, the value of the combo box does
not change.

What is the best way to tell if the value of the combo box is valid against
the new recordsource?

If the value is not valid, the unbound fields will be blank. So I can check
by looking to see if an unbound column is blank.

But eventually, that will fail when it comes up against a record where the
field is blank anyway.

I am using limit to list: I would like to clear the value if it is not valid
after changing the rowsource, but keep the value if it is still valid.

(david)
 
B

Brian Bastl

You're probably assigning the Rowsource in the AfterUpdate event of some
other control on your form.

Private Sub SomeControl_AfterUpdate()
'clear combo value
Me.MyCombo=""
'assign new rowsource
Me.MyCombo.RowSource = 'insert the SQL
'select first item in list
Me.MyCombo = Me.MyCombo.ItemData(0)
End Sub

Brian
 
A

Allen Browne

David, you already have the combo's new RowSource, so could you
OpenRecordset on that, and see if you can find the combo's value in
rs.Fields(Me.Combo1.BoundColumn -1) ?
 
M

Marshall Barton

david said:
When I change the rowsource of a combo box, the value of the combo box does
not change.

What is the best way to tell if the value of the combo box is valid against
the new recordsource?

If the value is not valid, the unbound fields will be blank. So I can check
by looking to see if an unbound column is blank.

But eventually, that will fail when it comes up against a record where the
field is blank anyway.

I am using limit to list: I would like to clear the value if it is not valid
after changing the rowsource, but keep the value if it is still valid.


David,
Check the combo box's ListIndex property for -1
 
D

david epsom dot com dot au

Excellent!

What I particularly like about this solution is that it
is clear as well as fast.

I confess that after 10+ years, our code still has a
variety of inferior methods for making this test.

(david)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top