IF
this is a continuous form
AND
you are filtering on 1 combo box
in the combo box AFTERUPDATE event:
Code:me.filter = "[field] = ' " & cboBox & " ' " 'single quotes exagerated for visiblilty. dont use spaces in reality. me.filterOn = true
if you are using MORE than 1 combo:
You cant use form boxes in a query if there's nothing in them..so..
Test all controls for a possible filter then build the where clause.
Code:if not isnull(cboState) then sWhere = sWhere & " and [state]='" & cboState & "'" if not IsNull(txtName) then sWhere = sWhere & " and [Name]='" & txtName & "'" if not IsNull(chkContact) then sWhere = sWhere & " and [Contact]=" & chkContact.value 'remove 1st And if len(sWhere)>0 then sWhere= mid(sWhere,5) 'just use the filter iLen = Len(sWhere) - 5 If iLen <= 0 Then me.filterOn = false Else me.filter = sWhere me.filterOn = true End If
What's the different between afterevent and on change ?IF
this is a continuous form
AND
you are filtering on 1 combo box
in the combo box AFTERUPDATE event:
Code:me.filter = "[field] = ' " & cboBox & " ' " 'single quotes exagerated for visiblilty. dont use spaces in reality. me.filterOn = true
if you are using MORE than 1 combo:
You cant use form boxes in a query if there's nothing in them..so..
Test all controls for a possible filter then build the where clause.
Code:if not isnull(cboState) then sWhere = sWhere & " and [state]='" & cboState & "'" if not IsNull(txtName) then sWhere = sWhere & " and [Name]='" & txtName & "'" if not IsNull(chkContact) then sWhere = sWhere & " and [Contact]=" & chkContact.value 'remove 1st And if len(sWhere)>0 then sWhere= mid(sWhere,5) 'just use the filter iLen = Len(sWhere) - 5 If iLen <= 0 Then me.filterOn = false Else me.filter = sWhere me.filterOn = true End If
AfterUpdate fires when the user leaves a control after having done something in it. If the user tabs into a control and tabs out without typing or changing the value, it won't fire.
Change fires *at every keystroke* in the control - i.e. whenever the Text (as opposed to Value) property of the control is changed.
AfterUpdate is almost surely what you want, if you want to redo a calculation when a new value has been established in your control. Change is useful if you want to trap individual keystrokes.
I just googled it