hi all
I have 2 lots of vba code I would like to merge together under one command button one that checks for null's and one that check for dates in a date range and has combo which also filters by client sorry my vba knowledge is little but I batting through it
but what I would like is if ckbnodate= false and cbnodate2= false and cbknoinvoice =false to ignore the code above and run the code below
to be honest I haven't got a clue where to start
any help will be much appreciated
Shane
I have 2 lots of vba code I would like to merge together under one command button one that checks for null's and one that check for dates in a date range and has combo which also filters by client sorry my vba knowledge is little but I batting through it
Code:
Dim strWhere As String
If Me.Ckbnodate = True And CkbNodate2 = True And cbknoinvoice = True Then
strWhere = "[Date Work Started] Is Null AND [Date Work Completed] Is Null and [Invoice Date] is Null"
ElseIf Me.Ckbnodate = True And CkbNodate2 = False And cbknoinvoice = False Then
strWhere = "[Date Work Started] Is Null AND Not [Date Work Completed] Is Null and Not [Invoice Date] is Null"
ElseIf Me.Ckbnodate = True And CkbNodate2 = False And cbknoinvoice = True Then
strWhere = "[Date Work Started] Is Null AND Not [Date Work Completed] Is Null and [Invoice Date] is Null"
ElseIf Me.Ckbnodate = True And CkbNodate2 = True And cbknoinvoice = False Then
strWhere = "[Date Work Started] Is Null AND [Date Work Completed] Is Null and not [Invoice Date] is Null"
ElseIf Me.Ckbnodate = False And CkbNodate2 = True And cbknoinvoice = False Then
strWhere = "Not [Date Work Started] Is Null AND [Date Work Completed] Is Null and not [Invoice Date] is Null"
ElseIf Me.Ckbnodate = False And CkbNodate2 = False And cbknoinvoice = True Then
strWhere = "[Date Work Started] Is Null AND not[Date Work Completed] Is Null and [Invoice Date] is Null"
ElseIf Me.Ckbnodate = False And CkbNodate2 = True And cbknoinvoice = True Then
strWhere = "Not [Date Work Started] Is Null AND [Date Work Completed] Is Null and [Invoice Date] is Null"
Else
strWhere = "Not [Date Work Started] Is Null AND Not [Date Work Completed] Is Null and Not[Invoice Date] is Null"
End If
DoCmd.OpenReport "rptgen", acViewPreview, , strWhere
Code:
Dim strReport As String
Dim strDateField As String
Dim strWhere As String
Dim lngView As Long
Const strcJetDate = "\#mm\/dd\/yyyy\#" 'Do NOT change it to match your local settings.
'DO set the values in the next 3 lines.
'Put your report name in these quotes.
strReport = "Input Report"
If Me.[ckfieldfilter] = True Then
strDateField = "[Date 1]" 'Put your field name in the square brackets in these quotes
ElseIf Me.[ckfieldfilter] = False Then
strDateField = "[Date Work Completed]"
End If
lngView = acViewReport 'Use acViewNormal to print instead of preview.
'Build the filter string.
If IsDate(Me.txtStartDate) Then
strWhere = "(" & strDateField & " >= " & Format(Me.txtStartDate, strcJetDate) & ")"
End If
If IsDate(Me.txtEndDate) Then
If strWhere <> vbNullString Then
strWhere = strWhere & " AND "
End If
strWhere = strWhere & "(" & strDateField & " < " & Format(Me.txtEndDate + 1, strcJetDate) & ")"
End If
If Len(Trim(Me.cboclient)) > 0 Then
If strWhere <> vbNullString Then
strWhere = strWhere & " AND "
End If
strWhere = strWhere & "(Client = '" & Me.cboclient & "')"
End If
If Len(Trim(Me.cboclient2)) > 0 Then
If strWhere <> vbNullString Then
strWhere = strWhere & " OR "
End If
strWhere = strWhere & "(Client = '" & Me.cboclient2 & "')"
End If
'Close the report if already open: otherwise it won't filter properly.
If CurrentProject.AllReports(strReport).IsLoaded Then
DoCmd.Close acReport, strReport
End If
'Open the report.
'Debug.Print strWhere 'Remove the single quote from the start of this line for debugging purposes.
DoCmd.OpenReport strReport, lngView, , strWhere
Exit_Handler:
Exit Sub
Err_Handler:
If Err.Number <> 2501 Then
MsgBox "Error " & Err.Number & ": " & Err.Description, vbExclamation, "Cannot open report"
End If
Resume Exit_Handler
End Sub
any help will be much appreciated
Shane
Last edited: