View Full Version : 3 Combo Boxes


Bluezman
05-15-2002, 08:09 AM
I'm trying to correctly code 3 combo boxes, using the VB below. (cboBody is working correctly sets the correct rowsource for cboNumber. cboBody gets its contents from a table listing Organization numbers.)

Private Sub cboBody_AfterUpdate()
Me![cboNumber].RowSource = "SELECT BodyNumber FROM" & _
" ActiveBodies WHERE [BodyType] = " & Me.cboBody & _
" ORDER BY BodyNumber"
Me![cboBody].Requery
End Sub

(Body types are 1, 2 or 3)

Private Sub cboNumber_AfterUpdate()
Me![cboName].RowSource = "SELECT mbrID, [Last Name], Suffix, [First Name], [Middle Name] FROM" & _
" MemberFormQuery WHERE [Chapter Number] = " & Me.cboNumber & _
" ORDER BY mbrID"
Me![cboName].Requery
End Sub

Private Sub cboName_AfterUpdate()
Dim rs As Object
Set rs = Me.Recordset.Clone
rs.FindFirst "[mbrID] = " & Str(Nz(Me![cboName], 0))
If Not rs.EOF Then Me.Bookmark = rs.Bookmark

Me![cboName] = ""
Me![cboName].Requery
Me![cboNumber] = ""
Me![cboNumber].Requery
Me![cboBody] = ""
Me![cboBody].Requery

End Sub

Is it possible for cboNumber to change the WHERE criteria (using IF statements) based on which BodyType was selected in cboBody? For example, if BodyType 1 was selected in cboBody, cboNumbers WHERE criteria would be the field [Chapter Number], but if BodyType 2 was selected, cboNumbers WHERE criteria would be changed to [Council Number]?

If you need more info, please let me know.

Thanks in advance!!

Bluez

Jack Cowley
05-15-2002, 08:34 AM
Create your SQL statement in the After Update event of the Body combo then set the Row Source of the Number combo to the SQL statement...

Dim strSQL as String
If Me.cboBody = 1 Then
strSQL = "SELECT..."
Me.cboNumber.RowSource = strSQL
rest of code....

You can use a variable for the criteria so you will only need one SQL statement.

Bluezman
05-15-2002, 09:06 AM
Thank you Jack! It's become quite the habit for me to be saying that to you and David R. recently. You guys are extremely helpful and I for one appreciate your time and effort.

Bluez