FrymanTCU
05-19-2008, 03:06 PM
Ok I had a cmd that was gather data from a form and then create a string to filter my subform. It has been working fine for a few weeks but today when I was changing part of an automated email, I broke the code... I don't know if it is a reference or what but I get a Run-Time error '40036' Method 'Form' of object '_SubForm' failed. Thanks in advance.
-Rich
Private Sub Search_Click()
Const cInvalidDateError As String = "You have entered an invalid date."
Dim strWhere As String
Dim strError As String
strWhere = "1=1"
If Not IsNull(Me.cboUserName) Then
'Create Predicate
strWhere = strWhere & " AND " & "[AUDIT HISTORY].[USER NAME] Like '*" & Me.cboUserName & "*'"
End If
If Not IsNull(Me.cboDocDescription) Then
'Add the predicate
strWhere = strWhere & " AND " & "[AUDIT HISTORY].[DOC DESCRIPTION] Like '*" & Trim(Me.cboDocDescription) & "*'"
End If
If Nz(Me.cboAuditDecision) <> "" Then
'Add it to the predicate - exact match
strWhere = strWhere & " AND " & "[AUDIT HISTORY].[AuditID] = " & Me.cboAuditDecision & ""
End If
If Nz(Me.BranchID) <> "" Then
'Add it to the predicate - exact match
strWhere = strWhere & " AND " & "[AUDIT HISTORY].[OFFICE] Like'*" & Format(Me.BranchID, "0000") & "*'"
End If
If Nz(Me.AccountNum) <> "" Then
'Add it to the predicate - exact match
strWhere = strWhere & " AND " & "[AUDIT HISTORY].[ACCOUNT BASE] = '" & Me.AccountNum & "'"
End If
' If Opened Date From
If IsDate(Me.OpenedDateFrom) Then
' Add it to the predicate - exact
strWhere = strWhere & " AND " & "[AUDIT HISTORY].[DOC CHANGE DATE]>= " & GetDateFilter(Me.OpenedDateFrom)
ElseIf Nz(Me.OpenedDateFrom) <> "" Then
strError = cInvalidDateError
End If
' If Opened Date To
If IsDate(Me.OpenedDateTo) Then
' Add it to the predicate - exact
strWhere = strWhere & " AND " & "[AUDIT HISTORY].[DOC CHANGE DATE]<= " & GetDateFilter(Me.OpenedDateTo)
ElseIf Nz(Me.OpenedDateTo) <> "" Then
strError = cInvalidDateError
End If
If strError <> "" Then
MsgBox strError
Else
'DoCmd.OpenForm "Browse Issues", acFormDS, , strWhere, acFormEdit, acWindowNormal
If Not Me.FormFooter.Visible Then
Me.FormFooter.Visible = True
DoCmd.MoveSize Height:=Me.WindowHeight + Me.FormFooter.Height
End If
Me.FollowUpSubForm.Form.Filter = strWhere
Me.FollowUpSubForm.Form.FilterOn = True
End If
End Sub
Function GetDateFilter(dtDate As Date) As String
' Date filters must be in MM/DD/YYYY format
GetDateFilter = "#" & Format(dtDate, "MM/DD/YYYY hh:mm:ss AM/PM") & "#"
End Function
-Rich
Private Sub Search_Click()
Const cInvalidDateError As String = "You have entered an invalid date."
Dim strWhere As String
Dim strError As String
strWhere = "1=1"
If Not IsNull(Me.cboUserName) Then
'Create Predicate
strWhere = strWhere & " AND " & "[AUDIT HISTORY].[USER NAME] Like '*" & Me.cboUserName & "*'"
End If
If Not IsNull(Me.cboDocDescription) Then
'Add the predicate
strWhere = strWhere & " AND " & "[AUDIT HISTORY].[DOC DESCRIPTION] Like '*" & Trim(Me.cboDocDescription) & "*'"
End If
If Nz(Me.cboAuditDecision) <> "" Then
'Add it to the predicate - exact match
strWhere = strWhere & " AND " & "[AUDIT HISTORY].[AuditID] = " & Me.cboAuditDecision & ""
End If
If Nz(Me.BranchID) <> "" Then
'Add it to the predicate - exact match
strWhere = strWhere & " AND " & "[AUDIT HISTORY].[OFFICE] Like'*" & Format(Me.BranchID, "0000") & "*'"
End If
If Nz(Me.AccountNum) <> "" Then
'Add it to the predicate - exact match
strWhere = strWhere & " AND " & "[AUDIT HISTORY].[ACCOUNT BASE] = '" & Me.AccountNum & "'"
End If
' If Opened Date From
If IsDate(Me.OpenedDateFrom) Then
' Add it to the predicate - exact
strWhere = strWhere & " AND " & "[AUDIT HISTORY].[DOC CHANGE DATE]>= " & GetDateFilter(Me.OpenedDateFrom)
ElseIf Nz(Me.OpenedDateFrom) <> "" Then
strError = cInvalidDateError
End If
' If Opened Date To
If IsDate(Me.OpenedDateTo) Then
' Add it to the predicate - exact
strWhere = strWhere & " AND " & "[AUDIT HISTORY].[DOC CHANGE DATE]<= " & GetDateFilter(Me.OpenedDateTo)
ElseIf Nz(Me.OpenedDateTo) <> "" Then
strError = cInvalidDateError
End If
If strError <> "" Then
MsgBox strError
Else
'DoCmd.OpenForm "Browse Issues", acFormDS, , strWhere, acFormEdit, acWindowNormal
If Not Me.FormFooter.Visible Then
Me.FormFooter.Visible = True
DoCmd.MoveSize Height:=Me.WindowHeight + Me.FormFooter.Height
End If
Me.FollowUpSubForm.Form.Filter = strWhere
Me.FollowUpSubForm.Form.FilterOn = True
End If
End Sub
Function GetDateFilter(dtDate As Date) As String
' Date filters must be in MM/DD/YYYY format
GetDateFilter = "#" & Format(dtDate, "MM/DD/YYYY hh:mm:ss AM/PM") & "#"
End Function