Hey Everyone:
I am trying to create a form where the person can choose the type of parameter (Equal To, Range, Less Than, etc.) to use for a report and thought VBA would be best. Here is my code to choose the parameter and then run the report:
Dim stDocName As String, strCriteria As String, prmSQL As String
DoCmd.OpenQuery "qryLoanReport_step_1", , acAdd
DoCmd.Close
Select Case Me.Parameters
Case "Range"
strCriteria = "Between "&Me.InputNumber1&" AND "&Me.InputNumber2
Case "Less Than"
strCriteria = "<" & Me.InputNumber1
Case "Equal To"
strCriteria = "=" & Me.InputNumber1
Case "Greater Than"
strCriteria = ">" & Me.InputNumber1
Case "Not Equal To"
strCriteria = "<>" & Me.InputNumber1
End Select
prmSQL = " SELECT tbl_Borrower_Personal_Information.Borrower_Social_Security_Number, tbl_Historical_Loan_Information.Lender_Case_Number," & _
" [Borrower_Last_Name] & ', ' & [Borrower_First_Name] AS [Full Name], tbl_Borrower_Personal_Information.Borrower_Home_Phone_Number, tbl_Borrower_Personal_Information.Borrower_Current_City, tbl_Borrower_Personal_Information.Borrower_Current_State_Abbreviation, tbl_Borrower_Personal_Information.Borrower_Email_Address," & _
" tbl_Historical_Loan_Information.Mortgage_Applied_Type, tbl_Historical_Loan_Information.Loan_Amount, tbl_Historical_Loan_Information.Loan_Interest_Rate, tbl_Historical_Loan_Information.Loan_Number_of_Months, tbl_Historical_Loan_Information.Amortization_Detail_Type_Description, tbl_Historical_Loan_Information.Purpose_of_Loan," & _
" tbl_Historical_Loan_Information.Subject_Appraisal_Value, tbl_Historical_Loan_Information.Subject_Loan_to_Value, tbl_Historical_Loan_Information.Loan_Closing_Date" & _
" FROM tbl_Borrower_Personal_Information INNER JOIN (tbl_Historical_Loan_Information INNER JOIN qryLoanReport_step_1 ON (tbl_Historical_Loan_Information.Borrower_Social_Security_Number = qryLoanReport_step_1.Borrower_Social_Security_Number) AND (tbl_Historical_Loan_Information.Loan_Closing_Date = qryLoanReport_step_1.FirstOfLoan_Closing_Date))" & _
" ON tbl_Borrower_Personal_Information.Borrower_Social_Security_Number = tbl_Historical_Loan_Information.Borrower_Social_Security_Number" & _
" WHERE (((tbl_Historical_Loan_Information.Loan_Interest_Rate)strCriteria))" & _
" ORDER BY [Borrower_Last_Name] & ', ' & [Borrower_First_Name], tbl_Historical_Loan_Information.Purpose_of_Loan, tbl_Historical_Loan_Information.Loan_Closing_Date DESC;"
DoCmd.SetWarnings False
DoCmd.RunSQL prmSQL
DoCmd.SetWarnings True
stDocName = "rptRecentLoanRates"
DoCmd.OpenReport stDocName, acPreview
I am having two areas of trouble:
1. I get a Expected:end of statement message regarding the
" AND " for my Case "Range" line
2. Also get syntax error (missing operator) message for my strCriteria field.
Help?
Thanks.
DMO
I am trying to create a form where the person can choose the type of parameter (Equal To, Range, Less Than, etc.) to use for a report and thought VBA would be best. Here is my code to choose the parameter and then run the report:
Dim stDocName As String, strCriteria As String, prmSQL As String
DoCmd.OpenQuery "qryLoanReport_step_1", , acAdd
DoCmd.Close
Select Case Me.Parameters
Case "Range"
strCriteria = "Between "&Me.InputNumber1&" AND "&Me.InputNumber2
Case "Less Than"
strCriteria = "<" & Me.InputNumber1
Case "Equal To"
strCriteria = "=" & Me.InputNumber1
Case "Greater Than"
strCriteria = ">" & Me.InputNumber1
Case "Not Equal To"
strCriteria = "<>" & Me.InputNumber1
End Select
prmSQL = " SELECT tbl_Borrower_Personal_Information.Borrower_Social_Security_Number, tbl_Historical_Loan_Information.Lender_Case_Number," & _
" [Borrower_Last_Name] & ', ' & [Borrower_First_Name] AS [Full Name], tbl_Borrower_Personal_Information.Borrower_Home_Phone_Number, tbl_Borrower_Personal_Information.Borrower_Current_City, tbl_Borrower_Personal_Information.Borrower_Current_State_Abbreviation, tbl_Borrower_Personal_Information.Borrower_Email_Address," & _
" tbl_Historical_Loan_Information.Mortgage_Applied_Type, tbl_Historical_Loan_Information.Loan_Amount, tbl_Historical_Loan_Information.Loan_Interest_Rate, tbl_Historical_Loan_Information.Loan_Number_of_Months, tbl_Historical_Loan_Information.Amortization_Detail_Type_Description, tbl_Historical_Loan_Information.Purpose_of_Loan," & _
" tbl_Historical_Loan_Information.Subject_Appraisal_Value, tbl_Historical_Loan_Information.Subject_Loan_to_Value, tbl_Historical_Loan_Information.Loan_Closing_Date" & _
" FROM tbl_Borrower_Personal_Information INNER JOIN (tbl_Historical_Loan_Information INNER JOIN qryLoanReport_step_1 ON (tbl_Historical_Loan_Information.Borrower_Social_Security_Number = qryLoanReport_step_1.Borrower_Social_Security_Number) AND (tbl_Historical_Loan_Information.Loan_Closing_Date = qryLoanReport_step_1.FirstOfLoan_Closing_Date))" & _
" ON tbl_Borrower_Personal_Information.Borrower_Social_Security_Number = tbl_Historical_Loan_Information.Borrower_Social_Security_Number" & _
" WHERE (((tbl_Historical_Loan_Information.Loan_Interest_Rate)strCriteria))" & _
" ORDER BY [Borrower_Last_Name] & ', ' & [Borrower_First_Name], tbl_Historical_Loan_Information.Purpose_of_Loan, tbl_Historical_Loan_Information.Loan_Closing_Date DESC;"
DoCmd.SetWarnings False
DoCmd.RunSQL prmSQL
DoCmd.SetWarnings True
stDocName = "rptRecentLoanRates"
DoCmd.OpenReport stDocName, acPreview
I am having two areas of trouble:
1. I get a Expected:end of statement message regarding the
" AND " for my Case "Range" line
2. Also get syntax error (missing operator) message for my strCriteria field.
Help?
Thanks.
DMO