Exporting Query Using SendTQ2Excel

CanWest

Registered User.
Local time
Today, 12:41
Joined
Sep 15, 2006
Messages
272
Hello everyone

I am attempting to use Bob Larson's export to excel function on a button on one of my forms.
The query I am basing the export on references values stored in a form. When I run the module i get an error To few parameters. Expected 4.
Coincidentally the query has for parameters in it. See the sql belo
Code:
SELECT tbl_Company.CompanyName, tbl_Company.Address1, tbl_Company.Address2, tbl_Company.City, tbl_Company.Province, tbl_Company.PostalCode, tbl_Company.Telephone, tbl_Company.Fax, tbl_Company.GeneralEmail, tbl_Company.Website, tbl_Company.Area, tbl_Company.CompanyCategory, tbl_Company.LastCallDate, tbl_Company.NextCallDate, tbl_Company.AssignedTo, tbl_Company.EnteredBy
FROM tbl_Company
WHERE (((tbl_Company.City) Like [Forms]![frm_MainMenu]![sfrm_Reports].[Form]![cboSelectCity] & "*") AND ((tbl_Company.Area) Like [Forms]![frm_MainMenu]![sfrm_Reports].[Form]![cboSelectAreaofCity] & "*") AND ((tbl_Company.CompanyCategory) Like [Forms]![frm_MainMenu]![sfrm_Reports].[Form]![cboSelectBusinessCategory] & "*") AND ((tbl_Company.EnteredBy) Like [Forms]![frm_MainMenu]![sfrm_Reports].[Form]![cboSelectEnteredby] & "*"))
ORDER BY tbl_Company.CompanyName;

However if I eliminate the where statement all is fine. See sql below

Code:
SELECT tbl_Company.CompanyName, tbl_Company.Address1, tbl_Company.Address2, tbl_Company.City, tbl_Company.Province, tbl_Company.PostalCode, tbl_Company.Telephone, tbl_Company.Fax, tbl_Company.GeneralEmail, tbl_Company.Website, tbl_Company.Area, tbl_Company.CompanyCategory, tbl_Company.LastCallDate, tbl_Company.NextCallDate, tbl_Company.AssignedTo, tbl_Company.EnteredBy
FROM tbl_Company
ORDER BY tbl_Company.CompanyName;`

Any suggestions would be greatly appreciated.
 
The SQl looks good. Each criteria in own set of brackets, whole criteria set enclosed in brackets also. Syntax looks good also.

Just thinking aloud (sometimes it makes the little grey cells spark:D)

I take it the SQL is from a query? Does the query run ok on its own?
Is the Form [frm_MainMenu]![sfrm_Reports] open?
Does the Form [frm_MainMenu]![sfrm_Reports] have valid data?
Have you tried running the query with hard wired parameters (just to check it works)?
 
The SQl looks good. Each criteria in own set of brackets, whole criteria set enclosed in brackets also. Syntax looks good also.

Just thinking aloud (sometimes it makes the little grey cells spark:D)

I take it the SQL is from a query? Does the query run ok on its own?
Is the Form [frm_MainMenu]![sfrm_Reports] open?
Does the Form [frm_MainMenu]![sfrm_Reports] have valid data?
Have you tried running the query with hard wired parameters (just to check it works)?
The query works fine on it's own, with hard coded parameters or with the form equivalent.

It is only when I run it in conjunction with the module that I get the error and only when the form elements are in the query
 

Users who are viewing this thread

Back
Top Bottom