Gasman
Enthusiastic Amateur
- Local time
- Today, 15:18
- Joined
- Sep 21, 2011
- Messages
- 16,834
Hi all,
After playing around with export specification for the RBS Bankline import today, I decided to change the code that I had created to show refund splits back to providers.
I originally wrote to a text file and then opened that, but as I discovered how to remove the double quotes on an export spec, I decide to change it to a spec and use TransferText.
qryClientRefunds
Query runs fine
I created an export spec called "ExportRefund" by following the instructions here
https://www.experts-exchange.com/questions/27982786/MS-Access-VBA-exporting-using-Specification.html particularly following the last instruction NOT to save the spec as I was doing previously and wondering why Access could not find it when it was staring me in the face.:banghead:
I get the error message in the attached pic but do not understand 'too few parameters, expected 0 ?'
Error occurs on the DoCmd.TransferText line
This is my old code
This is my new code in the form
CalcRefund is
What am I missing please.?
After playing around with export specification for the RBS Bankline import today, I decided to change the code that I had created to show refund splits back to providers.
I originally wrote to a text file and then opened that, but as I discovered how to remove the double quotes on an export spec, I decide to change it to a spec and use TransferText.
qryClientRefunds
Code:
SELECT Emails.CMS, Emails.Client, Emails.ThirdParty AS Donor, Sum(Emails.Amount) AS Donated, Calcrefund([CMS],[ThirdParty]) AS Refund
FROM Emails
WHERE (((Emails.Amount)>0))
GROUP BY Emails.CMS, Emails.Client, Emails.ThirdParty
HAVING (((Emails.CMS)=[Forms]![frmClientRefunds]![txtCMS]));
Query runs fine
I created an export spec called "ExportRefund" by following the instructions here
https://www.experts-exchange.com/questions/27982786/MS-Access-VBA-exporting-using-Specification.html particularly following the last instruction NOT to save the spec as I was doing previously and wondering why Access could not find it when it was staring me in the face.:banghead:
I get the error message in the attached pic but do not understand 'too few parameters, expected 0 ?'
Error occurs on the DoCmd.TransferText line
This is my old code
Code:
Sub ExportRefunds(lngCMS As Long)
Dim db As DAO.Database, rst As DAO.Recordset, qdf As DAO.QueryDef
Dim strQuery As String, strTextFile As String, strSql As String, strText As String, strFormat As String
Dim curBalance As Currency, curDonated As Currency, curBalanceCheck As Currency
Dim blnFile As Boolean
strQuery = "qryClientRefunds"
strTextFile = "c:\temp\CMS_Client_Refunds.txt"
Set db = CurrentDb()
strSql = "SELECT Emails.CMS, Emails.Client, Emails.ThirdParty, Sum(Emails.Amount) AS Donated, Calcrefund([CMS],[ThirdParty]) AS Refund FROM Emails"
strSql = strSql & " WHERE (((Emails.Amount)>0))"
strSql = strSql & " GROUP BY Emails.CMS, Emails.Client, Emails.ThirdParty"
strSql = strSql & " HAVING (((Emails.CMS)= " & lngCMS & "))"
'Debug.Print strSQL
Set rst = db.OpenRecordset(strSql)
' Open file to write to
Open strTextFile For Output As #1
Write #1, rst!Client
Write #1, "Donor" & vbTab & vbTab & "Donated" & vbTab & vbTab & "Refund"
Do While Not rst.EOF
blnFile = True
Write #1, rst!ThirdParty & vbTab & vbTab & Format(rst!Donated, "Currency") & vbTab & vbTab & Format(rst!Refund, "Currency")
curBalance = curBalance + rst!Refund
curDonated = curDonated + rst!Donated
rst.MoveNext
Loop
If blnFile Then
curBalanceCheck = DSum("Amount", "Emails", "CMS = " & lngCMS)
Write #1, "Total" & vbTab & vbTab & Format(curDonated, "Currency") & vbTab & vbTab & Format(curBalance, "Currency")
End If
If curBalanceCheck <> curBalance Then
MsgBox "Balance check has failed"
End If
Close #1
rst.Close
' Now open text file to copy & paste if we wrote anything
If blnFile Then
Shell ("Notepad.exe " & strTextFile)
End If
Set rst = Nothing
Set db = Nothing
End Sub
This is my new code in the form
Code:
Private Sub cmdRefund_Click()
Dim strFileName As String
If Len(Me.txtCMS) & "" = 0 Then
MsgBox "CMS reference is mandatory"
Exit Sub
End If
' We have a CMS number, so use it
strFileName = "C:\Temp\CMS_Client_Refund.txt"
'Call ExportRefunds(Me.txtCMS)
'TempVars("CMS").Value = Me.txtCMS.Value
DoCmd.TransferText , "ExportRefund", "qryClientRefunds", strFileName
DoCmd.Close acForm, Me.Name
End Sub
Code:
Public Function CalcRefund(plngCMS As Long, strDonor As String) As Currency
' Calculate % refund to donor
Dim curDonorDonated As Currency, curTotalDonated As Currency, curRemainder As Currency
curTotalDonated = DSum("Amount", "Emails", "Amount > 0 AND CMS = " & plngCMS)
curDonorDonated = DSum("Amount", "Emails", "Amount > 0 AND CMS = " & plngCMS & " AND ThirdParty = '" & strDonor & "'")
curRemainder = DSum("Amount", "Emails", "CMS = " & plngCMS)
'Debug.Print "Total " & curTotalDonated
'Debug.Print "Donor " & curDonorDonated
'Debug.Print "Remain " & curRemainder
' Now calc amount to refund
CalcRefund = Round(curDonorDonated / curTotalDonated * curRemainder, 2)
End Function
What am I missing please.?