Retrieving value of a combo box. (1 Viewer)

jesus_hairdo

Registered User.
Local time
Today, 11:54
Joined
Sep 28, 2001
Messages
32
i have a form with 2 combo boxes in. combo68 is a category chooser, and combo70 holds the a value from that category. (eg combo68= odd number, combo70=3)
What i want to do is to have combo70 dynamically change the choices depending on the category chosen in combo68.
i can get this to work for a new record by doing an afterupdate on combo70. This works great.
Now i am trying to get it to display the correct values for an existing record, i have tried using an if statement like the code below.
This works except that i want it to just display some text if combo68 if empty, at the moment this just displays an empty combo box.
Any ideas where i am going wrong ??

thanks

Jamie
------------------------
Private Sub Form_Current()
Dim category As String
category = Me.Combo68.DefaultValue
If IsNull(category) Then
Me.Combo70.RowSourceType = "Value List"
Me.Combo70.RowSource = "Select Category first"

Else
Me.Combo70.RowSourceType = "Table/Query"
Me.Combo70.RowSource = "SELECT [tbl_category_complaint_type].[complaint_type] FROM [tbl_category_complaint_type] where [tbl_category_complaint_type].[category] = '" & Me.Combo68.Value & "';"
End If
End Sub
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 06:54
Joined
Feb 19, 2002
Messages
43,408
The easiest way to do this is to have the query for combo2 refer to the combo1 value in its where clause -

Where SomeField = Forms!YourFormName!Combo1Name;

Then in the AfterUpdate event of combo1 place -

Me.Combo2.Requery

This method will take care of both new and existing records plus changes to existing records.
 

jstutz

Registered User.
Local time
Today, 11:54
Joined
Jan 28, 2000
Messages
80
Try this:


If IsNull(category) Then
Me.Combo70.RowSourceType = "Value List"
Me.Combo70.RowSource = "Select Category first"
Me.Combo70.DefaultValue= "'Select Category first'"
me.combo70.requery


Else
Me.Combo70.RowSourceType = "Table/Query"
Me.Combo70.RowSource = "SELECT [tbl_category_complaint_type].[complaint_type] FROM [tbl_category_complaint_type] where [tbl_category_complaint_type].[category] = '" & Me.Combo68.Value & "';"
End If
End Sub

HTH
Jamie

PS- Sorry Pat... you beat me to the punch!!!





[This message has been edited by jstutz (edited 01-14-2002).]
 

Users who are viewing this thread

Top Bottom