Check value of a combo box

jesus_hairdo

Registered User.
Local time
Today, 10:43
Joined
Sep 28, 2001
Messages
32
I have 2 combo boxes on a form,
when a value from box 1 (called Combo68) is selected this changes the values in box2 (called Combo70). (or more correctly changes the source sql script).

using this code,
-----------------
Private Sub Combo68_AfterUpdate()
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 Sub
--------------
This works fine on a new record, but when i go to an existing record box2 (combo70) shows the correct field value, BUT the combo box list shows the entries from the last new record.
I tried using this code
-----------------
Private Sub Combo70_BeforeUpdate(Cancel As Integer)
If IfEmpty(Me.Combo68.Value) 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
------------------------
However, all that happens is that the combo box2 (combo70) lists "select category first" regardless of whether the 1st combo box(combo68) has a value or not if no new/updated records have been entered. If a new/updated record has been entered it shows that records' values.

The Basic idea being that when entering a new record combo70 just reads "Select category first" (combo68), then when i select a value in combo68, combo70's values change.
if its an existing record with a value of combo68 it just uses that and selects the correct values

any ideas ??

cheers
 
You need to add code on the Forms Current Event to launch the code you have on the AfterUpdate event of Combo68.
 
Thanks that works well if you are viewing an existing record.
For a new record I want it to say "select category first" rather than have an empty combo box (as the select query returns no values)

cheers
 

Users who are viewing this thread

Back
Top Bottom