Help with query using multiple variables

S

sallen

Current query fields:
Account, SumPrincPmts, Transactions, PostDate

I am needing to run a query from a form (form name: frmbuyout) that
places the results in a report (Test). I need this query to Filter my
results by date and where the Principal pmts (are listed in table as a
LTD Sum) are less than the Total Transactions by account(currently in
the table the transactions are listed individually and not a sum of).
With the code below I can filter the information by date but I am
having trouble finding a way to also filter by pmts value being less
than the sum of the total transactions (this will need to be
determined by acct). I truly hope that this is not completely
confusing. Thank you in advance for any and all help.




Private Sub Command4_Click()
Dim strReport As String 'Name of report to open.
Dim strField As String 'Name of your date field.
Dim strWhere As String 'Where condition for OpenReport.
Const conDateFormat = "\#mm\/dd\/yyyy\#"


strReport = "Test"
strField = "PostDate"
strWhere = "("


If IsNull(Me.txtStartDate) Then
If Not IsNull(Me.txtEndDate) Then 'End date, but no
start.
strWhere = strWhere & strField & " < " &
Format(Me.txtEndDate, conDateFormat)
End If
Else
If IsNull(Me.txtEndDate) Then 'Start date, but no
End.
strWhere = strWhere & strField & " > " &
Format(Me.txtStartDate, conDateFormat)
Else 'Both start and end
dates.
strWhere = strWhere & strField & " Between " &
Format(Me.txtStartDate, conDateFormat) _
& " And " & Format(Me.txtEndDate, conDateFormat)
End If
End If
strWhere = strWhere & ")"
strWhere = strWhere



DoCmd.OpenReport strReport, acViewPreview, , strWhere

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

Top