Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

The IIF statement, a combo box and Null values 2

Status
Not open for further replies.

Timinator

Programmer
Apr 13, 2001
33
US
I created a combo box on a form that allows the user to choose to see the records that contain a value or the records that don't contain a value for a specificed field. The form is linked to a query. I used in IIF statement similar to this in the critera area for the field: IIF(Forms![Form]![ComboBox] = 'Contains Value', Not Null, Null). I am not sure if i am even close on this, but I can't seem to get any results. Any info would be great. Thanks. Tim
 
I am not very clear about what you need. It seems that you are trying to change the recordsource of a combox on the runtime. It surely works. However, you may need to requery the combox everytime the combox get focused.

For example:

Private Sub cboCustomer_GotFocus()
cboCustomer.Requery
End Sub

Seaport


 
Hi Tim,

Try this in the criteria of your query:

Like (IIF(IsNull(Forms![Form]![ComboBox]),"*",Forms![Form]![ComboBox]))

Should fly! ;-) Gord
ghubbell@total.net
 
Actually I'm trying to requery the entire form. So for example i have 4 records:
Product Num Product Name Comments
1 Hammer Tool
2 Wrench
3 Computer
4 Rake Claw rake


I want the combo box to query for a null value in the Comments field and only show the records that have comments. The combo box has 2 choices:
*Contains Value
*Contains No Value
I hope that makes more sense. Tim
 
Why not just set the filter first then requery the form.

For example

if combox="Contains Value" then

me.filter="isnull([comments]"
me.filteron=true
me.requery

Else

me.filter="not isnull([comments]"
me.filteron=true
me.requery

end if


Seaport
 
Hi Tim, Bang on Seaport! ;-)
You'd do like this in the "After Update" event (in visual basic) of your combobox. You'll also remove the criteria in your query. :) Gord
ghubbell@total.net
 
Almost there,

Thats 90% of what i'm looking for guys. Thanks for all of you input so far. The only problem is I have 5 other combo boxes that are linking to the query that change depending on whats in the query, and I can't seem to get the filter (that seaport suggested) to requery the combo boxes.

Thanks.

Tim
 
.....oh and i forgot to mention i tried: Combobox.Requery...and...Form.Requery


Thanks.

Tim
 
Hi Tim,
If You want to requery the form:

Me.Requery should work.

If you want to requery another combo:

Me.[NameOfTheOtherCombo].Requery

Should do it! :) Gord
ghubbell@total.net
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top