Check if value exist

  • Thread starter Thread starter Daniel
  • Start date Start date
D

Daniel

I have two combobox combo1and combo2. I need to check that if ANY value
exists in combo1, then run query1, and if ANY value exists in combo2, then
run query2, and if both combo1 and combo2 ANY value exist, then run query3.
Here is what I have and I may be way off.

Dim stDocName As String
If me.combo1 = -1 _
And Me.combo2 = 0 Then
stDocName = "Query1"
DoCmd.OpenQuery stDocName, acNormal, acEdit
ElseIf Me.combo1 = 0 _
And Me.combo2 = -1 Then
stDocName = "Query2"
DoCmd.OpenQuery stDocName, acNormal, acEdit
Else stDocName = "Query3"
DoCmd.OpenQuery stDocName, acNormal, acEdit
End If

I run it and nothing happens. Am I on the right track or do I have a hole
in my head?
Any help would be appreciated!

Daniel
 
In generalized terms of combo-box's value property, if there is only 1 item
selected, the combo-box's value property will be greater than -1. If no
items are selected in the combo-box, it's value will be -1. Provided that
the Multi-Select Property is set to either Simple or Extended on the combo
box, if it has multiple items selected, the Value property will return a
Null value. For your situation, I will assume that your multi-select
property is set to Single item only.

I can't say this is going to work for as long as the combo-box has the focus
as I have noticed a bug type issue with regards to listboxes not setting the
Selected property on items of the listbox properly while the Multi-Selection
Mode is set to Extended and the listbox has the focus, and I have not tried
the other 2 selection modes on listboxes or any on combo boxes, but this
should work at least for the time when neither combo-boxes doesn't have the
focus.

If Me.Combo1.Value > -1 Then
If Me.Combo2.Value > -1 Then
<The code to run query 3>
Else
<The code to run query 1>
End If
ElseIf Me.Combo2.Value > -1 Then
<The code to run query 2>
End If
 
Outstanding!!!

Thank You!

Ronald Dodge said:
In generalized terms of combo-box's value property, if there is only 1 item
selected, the combo-box's value property will be greater than -1. If no
items are selected in the combo-box, it's value will be -1. Provided that
the Multi-Select Property is set to either Simple or Extended on the combo
box, if it has multiple items selected, the Value property will return a
Null value. For your situation, I will assume that your multi-select
property is set to Single item only.

I can't say this is going to work for as long as the combo-box has the focus
as I have noticed a bug type issue with regards to listboxes not setting the
Selected property on items of the listbox properly while the Multi-Selection
Mode is set to Extended and the listbox has the focus, and I have not tried
the other 2 selection modes on listboxes or any on combo boxes, but this
should work at least for the time when neither combo-boxes doesn't have the
focus.

If Me.Combo1.Value > -1 Then
If Me.Combo2.Value > -1 Then
<The code to run query 3>
Else
<The code to run query 1>
End If
ElseIf Me.Combo2.Value > -1 Then
<The code to run query 2>
End If
 
Back
Top