Option Compare Database
Private Sub SearchCombo()
Dim sql As String
sql = "SELECT * FROM tbldata WHERE [Province] like '" & Nz(Me.Combo1, "*") & "' and [District] like '" & Nz(Me.Combo2, "*") & "'"
Forms!frmsearch!frmdata.Form.RecordSource = sql
Forms!frmsearch!frmdata.Form.Requery
If Not IsNull(Me.Combo1) Then
Me.Combo2.RowSource = "SELECT DISTINCT tbldata.District, tbldata.Province FROM tbldata WHERE (((tbldata.Province)=[forms]![frmsearch]![Combo1]));"
Else
Me.Combo2.RowSource = "SELECT DISTINCT tbldata.District FROM tbldata GROUP BY tbldata.District;"
End If
End Sub
Private Sub Combo1_AfterUpdate()
Me.Combo2 = Null
SearchCombo
End Sub
Private Sub Combo2_AfterUpdate()
SearchCombo
End Sub
Private Sub Combo2_GotFocus()
SearchCombo
End Sub
สร้างเงื่อนไขในการกำหนด RowSource ครับลองดูครับ