Avatar of Sandra Smith
Sandra SmithFlag for United States of America

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.TransactionDate Bewteen #" & Me.txtStartDate & "# AND #" & Me.txtEndDate & "#) AND "
ElseIf Not IsNull(Me.txtStartDate) And IsNull(Me.txtEndDate) Then
    strWhere = strWhere & " tblAccountTransactions.TransactionDate >=  #" & Me.txtStartDate & "# AND "
End If

If Not IsNull(Me.cboAccount) Then
     strWhere = strWhere & " tblAccountTransactions.AccountId = '" & Me.cboAccount.Column(0) & "' AND "
End If

intLength = Len(strWhere) - 5
strWhere = Left(strWhere, intLength)

If strFilter = "Filter" Then
    Forms!frmTransactions!sfrmaccountTransactions.Form.RecordSource = strSelect & " WHERE " & strWhere
'    Me.sfrmaccountTransactions.Forms.Requery
ElseIf strFilter = "Clear Filter" Then
    Forms!frmTransactions!sfrmaccountTransactions.Form.RecordSource = strSelect
'    Me!sfrmaccountTransactions.Form.Requery
End If

Exit_ErrorHandler:
    Exit Sub
ErrorHandler:
    MsgBox "Error Number: " & Err.Number & " Description: " & Err.Description
    Resume Exit_ErrorHandler
End Sub
Microsoft AccessProgrammingVisual Basic ClassicVBA

Avatar of undefined
Last Comment
Sandra Smith
ASKER CERTIFIED SOLUTION
Avatar of Sandra Smith
Sandra Smith
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Sandra Smith
Sandra Smith
Flag of United States of America image

ASKER

resolved myself.
Microsoft Access
Microsoft Access

Microsoft Access is a rapid application development (RAD) relational database tool. Access can be used for both desktop and web-based applications, and uses VBA (Visual Basic for Applications) as its coding language.

226K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo