I have researched on here how to print the results of a query to a text file
I put the code in and I get an error on the openrecordset line
the error says "too few parameters, expected 4"
I tried the query in another report I export to excel and the query works
I tried printing the whole table using "Select * from tbl_Customers" and it works????
here is the code:
Dim rst As DAO.Recordset
Set rst = CurrentDb.OpenRecordset("qryBell1", dbOpenSnapshot)
Dim fs, TextFile
Set fs = CreateObject("Scripting.FileSystemObject")
Set TextFile = fs.CreateTextFile(pathname, True)
Do Until rst.EOF = True
TextFile.writeline (rst!Phone & rst!CustID & rst!AccountNumber & rst!Name & rst!LatestStatus & rst!LatestContactDate)
rst.MoveNext
Loop
TextFile.Close
rst.Close
Set rst = Nothing
Here is the query qryBell1
SELECT tbl_Customers.Phone, tbl_Customers.CustID, tbl_Customers.AccountNumber, tbl_Customers.Name, tbl_Status.Description AS LastStatus, tbl_Customers.LatestContactDate AS LastContactDate
FROM (tbl_Customers INNER JOIN tbl_Campaigns ON tbl_Customers.CampaignID = tbl_Campaigns.CampaignID) LEFT JOIN tbl_Status ON tbl_Customers.LatestStatus = tbl_Status.StatusID
WHERE (((tbl_Customers.LatestContactDate)>=[Forms]![frmQueryMenu]![StartDate] & " 0:00:01 AM" And (tbl_Customers.LatestContactDate)<=[Forms]![frmQueryMenu]![EndDate] & " 11:59:59 PM") AND ((tbl_Customers.CampaignID) Like "*" & [Forms]![frmQueryMenu]![cboCampaign]) AND ((tbl_Status.StatusID) Like "*" & [Forms]![frmQueryMenu]![cboStatus])) OR (((tbl_Customers.LatestContactDate)>=[Forms]![frmQueryMenu]![StartDate] And (tbl_Customers.LatestContactDate)<=[Forms]![frmQueryMenu]![EndDate]) AND ((tbl_Status.StatusID) Is Null));
the query returns 6 fields for printing and can filter based on whether 3 fields are filled or not on the form - Date, Campaign, Status
I put the code in and I get an error on the openrecordset line
the error says "too few parameters, expected 4"
I tried the query in another report I export to excel and the query works
I tried printing the whole table using "Select * from tbl_Customers" and it works????
here is the code:
Dim rst As DAO.Recordset
Set rst = CurrentDb.OpenRecordset("qryBell1", dbOpenSnapshot)
Dim fs, TextFile
Set fs = CreateObject("Scripting.FileSystemObject")
Set TextFile = fs.CreateTextFile(pathname, True)
Do Until rst.EOF = True
TextFile.writeline (rst!Phone & rst!CustID & rst!AccountNumber & rst!Name & rst!LatestStatus & rst!LatestContactDate)
rst.MoveNext
Loop
TextFile.Close
rst.Close
Set rst = Nothing
Here is the query qryBell1
SELECT tbl_Customers.Phone, tbl_Customers.CustID, tbl_Customers.AccountNumber, tbl_Customers.Name, tbl_Status.Description AS LastStatus, tbl_Customers.LatestContactDate AS LastContactDate
FROM (tbl_Customers INNER JOIN tbl_Campaigns ON tbl_Customers.CampaignID = tbl_Campaigns.CampaignID) LEFT JOIN tbl_Status ON tbl_Customers.LatestStatus = tbl_Status.StatusID
WHERE (((tbl_Customers.LatestContactDate)>=[Forms]![frmQueryMenu]![StartDate] & " 0:00:01 AM" And (tbl_Customers.LatestContactDate)<=[Forms]![frmQueryMenu]![EndDate] & " 11:59:59 PM") AND ((tbl_Customers.CampaignID) Like "*" & [Forms]![frmQueryMenu]![cboCampaign]) AND ((tbl_Status.StatusID) Like "*" & [Forms]![frmQueryMenu]![cboStatus])) OR (((tbl_Customers.LatestContactDate)>=[Forms]![frmQueryMenu]![StartDate] And (tbl_Customers.LatestContactDate)<=[Forms]![frmQueryMenu]![EndDate]) AND ((tbl_Status.StatusID) Is Null));
the query returns 6 fields for printing and can filter based on whether 3 fields are filled or not on the form - Date, Campaign, Status