Dependent combo boxes and filtering a report by a form...

A

allie357

can anyone tell me what is wrong with this code

See the trick is i have dependent combo boxes and I need to be able to
leave one blank to filter as well. The fiter works with the code below
but not if I leave the DeptName combo blank which is dependent on RC
name with its query... I have no idea how to fix it. I would like the
option of leaving it blank.

Code:
--------------------------------------------------------------------------------

Private Sub Apply_Filter1_Click() Dim strRCName As String Dim
strDeptName As String Dim strFilter As String ' Check that the
report is open If SysCmd(acSysCmdGetObjectState, acReport,
"rpt_Violations_by_RC_x Violations") <> acObjStateOpen Then
MsgBox "You must open the report first." Exit Sub End If '
Build criteria string for RCName field If
IsNull(Me.CboRCName.Value) Then strRCName = "Like '*'" Else
strRCName = "='" & Me.CboRCName.Value & "'" End If ' Build
criteria string for DeptName field If IsNull(Me.cboDeptName.Value)
Then strDeptName = "Like '*'" Else strDeptName =
"='" & Me.cboDeptName.Value & "'" End If ' Combine criteria strings
into a WHERE clause for the filter strFilter = "[RCName] " &
strRCName & " AND [DeptName] " & strDeptName ' Apply the filter and
switch it on With Reports![rpt_Violations_by_RC_x Violations]
.Filter = strFilter .FilterOn = True End With End Sub
Private Sub CboRCName_AfterUpdate() Me!cboDeptName.Requery End Sub
Private Sub CboRCName_Change() 'Set value of combo box equal to an
empty string Me!cboDeptName.Value = "" End Sub Private Sub
Form_Open(Cancel As Integer) Me!CboRCName.Value = ""
Me!cboDeptName.Value = "" End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top