Sandra Smith
asked on
Change recorsource for child form based on Criteia selected in Parent form VBA ACCESS 2010
I am trying to get a child form to changes its record source based on criteria the user selects from the parent form. the below does create the record select string correctly, but I cannot get it to recognize the child form. I have commented out the requery as it errors our when it hits the recordsource setting.
Private Sub FilterForm(strFilter As String)
On Error GoTo ErrorHandler
Dim strSelect As String
Dim dteStartDate As Date
Dim dteEndDate As Date
Dim strAccountID As String
Dim strWhere As String
Dim intLength As Integer
strSelect = "SELECT * FROM tblAccountTransactions"
If Not IsNull(Me.txtStartDate) And Not IsNull(Me.txtEndDate) Then
strWhere = "(tblAccountTransactions.T ransaction Date Bewteen #" & Me.txtStartDate & "# AND #" & Me.txtEndDate & "#) AND "
ElseIf Not IsNull(Me.txtStartDate) And IsNull(Me.txtEndDate) Then
strWhere = strWhere & " tblAccountTransactions.Tra nsactionDa te >= #" & Me.txtStartDate & "# AND "
End If
If Not IsNull(Me.cboAccount) Then
strWhere = strWhere & " tblAccountTransactions.Acc ountId = '" & Me.cboAccount.Column(0) & "' AND "
End If
intLength = Len(strWhere) - 5
strWhere = Left(strWhere, intLength)
If strFilter = "Filter" Then
Forms!frmTransactions!sfrm accountTra nsactions. Form.Recor dSource = strSelect & " WHERE " & strWhere
' Me.sfrmaccountTransactions .Forms.Req uery
ElseIf strFilter = "Clear Filter" Then
Forms!frmTransactions!sfrm accountTra nsactions. Form.Recor dSource = strSelect
' Me!sfrmaccountTransactions .Form.Requ ery
End If
Exit_ErrorHandler:
Exit Sub
ErrorHandler:
MsgBox "Error Number: " & Err.Number & " Description: " & Err.Description
Resume Exit_ErrorHandler
End Sub
Private Sub FilterForm(strFilter As String)
On Error GoTo ErrorHandler
Dim strSelect As String
Dim dteStartDate As Date
Dim dteEndDate As Date
Dim strAccountID As String
Dim strWhere As String
Dim intLength As Integer
strSelect = "SELECT * FROM tblAccountTransactions"
If Not IsNull(Me.txtStartDate) And Not IsNull(Me.txtEndDate) Then
strWhere = "(tblAccountTransactions.T
ElseIf Not IsNull(Me.txtStartDate) And IsNull(Me.txtEndDate) Then
strWhere = strWhere & " tblAccountTransactions.Tra
End If
If Not IsNull(Me.cboAccount) Then
strWhere = strWhere & " tblAccountTransactions.Acc
End If
intLength = Len(strWhere) - 5
strWhere = Left(strWhere, intLength)
If strFilter = "Filter" Then
Forms!frmTransactions!sfrm
' Me.sfrmaccountTransactions
ElseIf strFilter = "Clear Filter" Then
Forms!frmTransactions!sfrm
' Me!sfrmaccountTransactions
End If
Exit_ErrorHandler:
Exit Sub
ErrorHandler:
MsgBox "Error Number: " & Err.Number & " Description: " & Err.Description
Resume Exit_ErrorHandler
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER