Combo Box through IIF for Query Criteria (1 Viewer)

Hero4th

New member
Local time
Yesterday, 19:16
Joined
Mar 22, 2018
Messages
4
Hi everybody, I have a combobox cmbTran in FormA that displays the values
TranID Name
1 A
2 B
3 C

cmbTran hides the TranID

I want to read the value selected in cmbTran combo box to use it as Criteria in a query for another combobox in the same FormA, i tried to use this criteria:

IIf([Forms]![FormA]![cmbTran] = 1,"LocationX","LocationY")

I believe that the value in cmbTran should be the TranID selected. I do not know what is wrong with my Criteria, thank you for the help =)
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 10:16
Joined
May 7, 2009
Messages
19,242
Your syntax is correct but yiu need to Requery the ither combo for the new vakue to take effect
 

Hero4th

New member
Local time
Yesterday, 19:16
Joined
Mar 22, 2018
Messages
4
You are completely right @arnelgp thank you very much!!!
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 10:16
Joined
May 7, 2009
Messages
19,242

Hero4th

New member
Local time
Yesterday, 19:16
Joined
Mar 22, 2018
Messages
4
I have another problem now, once I set it up, it works perfectly, but if i close the database and open it again, it stops workin, it asks me for the parameter that first combobox, gives back. But if I delete both combo boxes and start anew, it works again.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 10:16
Joined
May 7, 2009
Messages
19,242
Where did you put the Requery if the 2nd cimbo. Should be on the AfterUpdate event of the first.
 

Hero4th

New member
Local time
Yesterday, 19:16
Joined
Mar 22, 2018
Messages
4
Thank you arnel, I search in several places and found the answer in youtube.

/watch?v=l3OMeV4jRjw&t=48s minute 15:00

I needed to requery and clean the info, and the combo2 had to be disabled forehand.

Private Sub Combo1_AfterUpdate()
With Me.Combo2
.Requery
.Value = ""
.Enabled = True
End With
End Sub

Hopefully this post will benefit someone in the future.
Thank you for your time and attention @arnelgp , cheers!
 

Pat Hartman

Super Moderator
Staff member
Local time
Yesterday, 22:16
Joined
Feb 19, 2002
Messages
43,275
Thanks for posting back but there is something else awry because you should not have to enable the combo. It should not have been disabled unless you did that yourself in some other code.
 

Users who are viewing this thread

Top Bottom