Gasman
Enthusiastic Amateur
- Local time
- Today, 00:09
- Joined
- Sep 21, 2011
- Messages
- 16,450
Hi all,
I have created a query qryInvoice2 that will produce what I want to export to Excel for emailing on. I had to create qryInvoice1 to supply some of the data as I got the joins problem again.
I will be creating the queries in VBA, but am a little puzzled on how to go about it.
qryInvoice1 at present has a date parameter in it which I currently key in when asked, but it will eventually come from an unbound textbox on a form.
qryInvoice2 will also have a parameter that will be supplied from a recordset
My plan of attack is
Read recordset of Submitters
Loop through recordset of submitters
For each submitter execute qryInvoice2 with SubmitterID as parameter
Write data from qryInvoice2 to Excel
Repeat until eof recordset of Submitters
However my form is calling qryInvoice2, so how do I get the date on the form to the first query.
Is my structure incorrect that is causing me this problem.
I am trying to base this process on something I created at another workplace a year or so ago and is shown below as well for clarity.
As you can see I have tried to give the text control value to qryInvoice1, but I get the error message 'two few parameters Expected 1'
At present I am just trying to build the process in small steps, testing as I go.
qryinvoice1
qryInvoice2 (without extra criteria for submitterID)
Old code
I have created a query qryInvoice2 that will produce what I want to export to Excel for emailing on. I had to create qryInvoice1 to supply some of the data as I got the joins problem again.
I will be creating the queries in VBA, but am a little puzzled on how to go about it.
qryInvoice1 at present has a date parameter in it which I currently key in when asked, but it will eventually come from an unbound textbox on a form.
qryInvoice2 will also have a parameter that will be supplied from a recordset
My plan of attack is
Read recordset of Submitters
Loop through recordset of submitters
For each submitter execute qryInvoice2 with SubmitterID as parameter
Write data from qryInvoice2 to Excel
Repeat until eof recordset of Submitters
However my form is calling qryInvoice2, so how do I get the date on the form to the first query.
Is my structure incorrect that is causing me this problem.
I am trying to base this process on something I created at another workplace a year or so ago and is shown below as well for clarity.
As you can see I have tried to give the text control value to qryInvoice1, but I get the error message 'two few parameters Expected 1'
At present I am just trying to build the process in small steps, testing as I go.
qryinvoice1
Code:
PARAMETERS [Forms]![frmCreateInvoices]![txtInvoiceDate] DateTime;
SELECT tblStockTraded.TradeDate, tblSVSTrades.TradeType, tblSVSTrades.NetCost, tblSVSTrades.BuySell, tblStockTraded.Stock, tblStockTraded.IntroducerInvoicedDate, tblSVSTrades.SVSTradesID, tblSVSTrades.SVSAccount
FROM tblStockTraded INNER JOIN tblSVSTrades ON (tblStockTraded.Stock = tblSVSTrades.Stock) AND (tblStockTraded.TradeDate = tblSVSTrades.TradeDate);
qryInvoice2 (without extra criteria for submitterID)
Code:
SELECT qryInvoice1.TradeDate, tblClient.SVS_Account, tblClient.Forename, tblClient.Surname, qryInvoice1.TradeType, qryInvoice1.NetCost, qryInvoice1.BuySell, tblSubmitter.SubmitterName, tblIntroCommission.IntroCommission, qryInvoice1.Stock, tblIntroCommission.SubmitterID
FROM ((qryInvoice1 INNER JOIN tblCommission ON qryInvoice1.SVSTradesID = tblCommission.TradeID) INNER JOIN tblClient ON qryInvoice1.SVSAccount = tblClient.SVS_Account) INNER JOIN (tblIntroCommission INNER JOIN tblSubmitter ON tblIntroCommission.SubmitterID = tblSubmitter.SubmitterID) ON tblCommission.CommissionID = tblIntroCommission.CommissionID;
Old code
Code:
Private Sub cmdAllocate_Click()
On Error GoTo Err_Handler
Dim dbsPA As Database
Dim rstWA As Recordset
Dim rstPA As Recordset
Dim strSQLWA As String, strSQLPA As String
Dim strProduct As String, strMethod As String, StrQueue As String, strUser As String, strProgress As String
Dim intAllocate As Integer, intLoop As Integer, lngTotalAllocated As Long
Dim curLimit As Long, curAmount As Long
Dim blnShort As Boolean
'Set dbsPA = OpenDatabase("PA_Allocation")
Set dbsPA = CurrentDb()
'SQL statement to get Payment Analysts
strSQLPA = "SELECT Analyst.File_ID, Analyst.Full_Name, Analyst.Queue, Analyst.Product, Analyst.Pay_Method, Analyst.Workstream, Analyst.Allocation, Analyst.Received, Analyst.Working "
strSQLPA = strSQLPA & "FROM Analyst WHERE (((Analyst.Working)=True)) ;"
' SQL statemnt to get data to be allocated
Set rstPA = dbsPA.OpenRecordset(strSQLPA)
'WE are progressing, so open Progress form that will act as a status update to user
'DoCmd.OpenForm "Progress"
'Forms!Progress.txtProgress.Value = " Starting Allocation..."
'Forms!Progress.Refresh
Do While Not rstPA.EOF
' First get the extra criteria for the recordset
strProduct = Chr$(39) & rstPA.Fields("Product") & Chr$(39)
strMethod = Chr$(39) & rstPA.Fields("Pay_Method") & Chr$(39)
StrQueue = Chr$(39) & rstPA.Fields("Queue") & Chr$(39)
strUser = rstPA.Fields("Full_Name")
intAllocate = rstPA.Fields("Allocation")
' Payment limits are £5000 or £100,000
If rstPA.Fields("Workstream") = "Under 5K" Then
curLimit = 5000
Else
curLimit = 100000
End If
strSQLWA = "SELECT Daily_Work_Allocation.Amount, Daily_Work_Allocation.Process_Payment_Cashiers_allocated_to_name, Daily_Work_Allocation.payment_method, Daily_Work_Allocation.product_01, Daily_Work_Allocation.Payment_Case_Awaiting_Payment_allocated_to_name FROM Daily_Work_Allocation "
strSQLWA = strSQLWA & "WHERE (((Daily_Work_Allocation.Payment_Case_Awaiting_Payment_allocated_to_name) = '') AND ((Daily_Work_Allocation.Process_Payment_Cashiers_allocated_to_name)= " & StrQueue & ") AND ((Daily_Work_Allocation.payment_method)=" & strMethod & ") AND ((Daily_Work_Allocation.product_01)=" & strProduct & ")"
strSQLWA = strSQLWA & " AND ((Daily_Work_Allocation.Status) = '" & Me.cmbStatus & "'));"
' MsgBox strSQLWA
Set rstWA = dbsPA.OpenRecordset(strSQLWA, dbOpenDynaset)
intLoop = 0
If Not rstWA.EOF Then
rstWA.MoveFirst
Else
MsgBox "No payments found for " & strProduct & " " & strMethod & " for queue " & StrQueue
End If
' Debug.Print rstWA.RecordCount
Do While intLoop < intAllocate And Not rstWA.EOF
curAmount = rstWA.Fields("amount")
' Check the PA is authorised for the amount of payment
If curAmount <= curLimit Then
With rstWA
.Edit
.Fields("Payment_Case_Awaiting_Payment_allocated_to_name").Value = strUser
.Update
End With
intLoop = intLoop + 1
End If
rstWA.MoveNext
Loop
lngTotalAllocated = lngTotalAllocated + intLoop
'Now update Analyst table with amount allocated.
With rstPA
.Edit
.Fields("Received").Value = .Fields("Received").Value + intLoop
.Update
End With
' Now close WA ready for next select
rstWA.Close
rstPA.MoveNext
Loop
' Now refresh the Crosstab datasheet
' Me.[Daily_Work_Allocation_Crosstab_subform].Form.Refresh
Set dbsPA = Nothing
Set rstPA = Nothing
Set rstWA = Nothing
Me.Refresh
MsgBox lngTotalAllocated & " payments allocated..."
Err_Exit:
Exit Sub
Err_Handler:
MsgBox "Error " & Err.Number & " " & Err.Description
Resume Err_Exit
End Sub