Help, Error Message...Too Few parameters. Expected 3.

G

Guest

Trying to Export items from a Query "CalenderExport Q" (See Query Below) that
uses imputs from a combo box in a form. Using a function to export the
records to Outlook - However, When it gets to Set rst =
oDataBase.OpenRecordset("CalendarExport Q"), it gives me an error "Too Few
parameters. Expected 3." How can I have it call the records that show when I
open the query?

Function ExportCalendartoOutlook()

Dim oDataBase As DAO.Database
Dim rst As DAO.Recordset
Set oDataBase = CurrentDb
Set rst = oDataBase.OpenRecordset("CalendarExport Q")

More code here, doesn't matter.....

End Function


CalendarExport Q

SELECT [Master Planned].Date, [Activity] & " / " & [Vendor] & " / " &
[Customer Forecasts]!Name AS Subject, [Master Planned].Comments AS Body,
"Sales Plan" AS Category
FROM [Branch Master] LEFT JOIN ([Customer Forecasts] RIGHT JOIN [Master
Planned] ON [Customer Forecasts].[Customer ID] = [Master Planned].[Customer
ID]) ON [Branch Master].[Branch ID] = [Master Planned].[Branch ID]
WHERE ((([Master Planned].Date) Is Not Null) AND
((IIf([Forms]![CalendarExport]![Vendor] Is Not
Null,[Vendor]=[Forms]![CalendarExport]![Vendor],[Vendor] Is Not
Null))<>False) AND ((IIf([Forms]![CalendarExport]![Activity] Is Not
Null,[Activity]=[Forms]![CalendarExport]![Activity],[Activity] Is Not
Null))<>False) AND ((IIf([Forms]![CalendarExport]![Salesperson] Is Not
Null,[Salesperson]=[Forms]![CalendarExport]![Salesperson],[Salesperson] Is
Not Null))<>False))
ORDER BY [Master Planned].Date;
 
R

Rob Oldfield

Access is unable to (automatically) evaluate form controls in that context.
Try this:

Dim db As Database
Set db = CurrentDb()
Dim prm As Parameter
Dim qdf As QueryDef
Set qdf = db.QueryDefs("qryApndIndTable")
For Each prm In qdf.Parameters
prm.Value = Eval(prm.Name)
Next
qdf.Execute dbFailOnError

Dim oDataBase As DAO.Database
Dim rst As DAO.Recordset
Set oDataBase = CurrentDb

Dim prm As Parameter
Dim qdf As QueryDef
Set qdf = db.QueryDefs("CalendarExport Q")
For Each prm In qdf.Parameters
prm.Value = Eval(prm.Name)
Next

Set rst = qdf.openrecordset
 
G

Guest

Worked Great!

Thanks Much!

Ben

Rob Oldfield said:
Access is unable to (automatically) evaluate form controls in that context.
Try this:

Dim db As Database
Set db = CurrentDb()
Dim prm As Parameter
Dim qdf As QueryDef
Set qdf = db.QueryDefs("qryApndIndTable")
For Each prm In qdf.Parameters
prm.Value = Eval(prm.Name)
Next
qdf.Execute dbFailOnError

Dim oDataBase As DAO.Database
Dim rst As DAO.Recordset
Set oDataBase = CurrentDb

Dim prm As Parameter
Dim qdf As QueryDef
Set qdf = db.QueryDefs("CalendarExport Q")
For Each prm In qdf.Parameters
prm.Value = Eval(prm.Name)
Next

Set rst = qdf.openrecordset



Ben Adams said:
Trying to Export items from a Query "CalenderExport Q" (See Query Below) that
uses imputs from a combo box in a form. Using a function to export the
records to Outlook - However, When it gets to Set rst =
oDataBase.OpenRecordset("CalendarExport Q"), it gives me an error "Too Few
parameters. Expected 3." How can I have it call the records that show when I
open the query?

Function ExportCalendartoOutlook()

Dim oDataBase As DAO.Database
Dim rst As DAO.Recordset
Set oDataBase = CurrentDb
Set rst = oDataBase.OpenRecordset("CalendarExport Q")

More code here, doesn't matter.....

End Function


CalendarExport Q

SELECT [Master Planned].Date, [Activity] & " / " & [Vendor] & " / " &
[Customer Forecasts]!Name AS Subject, [Master Planned].Comments AS Body,
"Sales Plan" AS Category
FROM [Branch Master] LEFT JOIN ([Customer Forecasts] RIGHT JOIN [Master
Planned] ON [Customer Forecasts].[Customer ID] = [Master Planned].[Customer
ID]) ON [Branch Master].[Branch ID] = [Master Planned].[Branch ID]
WHERE ((([Master Planned].Date) Is Not Null) AND
((IIf([Forms]![CalendarExport]![Vendor] Is Not
Null,[Vendor]=[Forms]![CalendarExport]![Vendor],[Vendor] Is Not
Null))<>False) AND ((IIf([Forms]![CalendarExport]![Activity] Is Not
Null,[Activity]=[Forms]![CalendarExport]![Activity],[Activity] Is Not
Null))<>False) AND ((IIf([Forms]![CalendarExport]![Salesperson] Is Not
Null,[Salesperson]=[Forms]![CalendarExport]![Salesperson],[Salesperson] Is
Not Null))<>False))
ORDER BY [Master Planned].Date;
 
R

Rob Oldfield

No problem. I hope you realised that I completely screwed the last post and
included repetitions. Should be:

Dim oDataBase As DAO.Database
Dim rst As DAO.Recordset
Set oDataBase = CurrentDb

Dim prm As Parameter
Dim qdf As QueryDef
Set qdf = db.QueryDefs("CalendarExport Q")
For Each prm In qdf.Parameters
prm.Value = Eval(prm.Name)
Next
Set rst = qdf.openrecordset
....do work
rst.close
set db=nothing



Ben Adams said:
Worked Great!

Thanks Much!

Ben

Rob Oldfield said:
Access is unable to (automatically) evaluate form controls in that context.
Try this:

Dim db As Database
Set db = CurrentDb()
Dim prm As Parameter
Dim qdf As QueryDef
Set qdf = db.QueryDefs("qryApndIndTable")
For Each prm In qdf.Parameters
prm.Value = Eval(prm.Name)
Next
qdf.Execute dbFailOnError

Dim oDataBase As DAO.Database
Dim rst As DAO.Recordset
Set oDataBase = CurrentDb

Dim prm As Parameter
Dim qdf As QueryDef
Set qdf = db.QueryDefs("CalendarExport Q")
For Each prm In qdf.Parameters
prm.Value = Eval(prm.Name)
Next

Set rst = qdf.openrecordset



Ben Adams said:
Trying to Export items from a Query "CalenderExport Q" (See Query
Below)
that
uses imputs from a combo box in a form. Using a function to export the
records to Outlook - However, When it gets to Set rst =
oDataBase.OpenRecordset("CalendarExport Q"), it gives me an error "Too Few
parameters. Expected 3." How can I have it call the records that show when I
open the query?

Function ExportCalendartoOutlook()

Dim oDataBase As DAO.Database
Dim rst As DAO.Recordset
Set oDataBase = CurrentDb
Set rst = oDataBase.OpenRecordset("CalendarExport Q")

More code here, doesn't matter.....

End Function


CalendarExport Q

SELECT [Master Planned].Date, [Activity] & " / " & [Vendor] & " / " &
[Customer Forecasts]!Name AS Subject, [Master Planned].Comments AS Body,
"Sales Plan" AS Category
FROM [Branch Master] LEFT JOIN ([Customer Forecasts] RIGHT JOIN [Master
Planned] ON [Customer Forecasts].[Customer ID] = [Master Planned].[Customer
ID]) ON [Branch Master].[Branch ID] = [Master Planned].[Branch ID]
WHERE ((([Master Planned].Date) Is Not Null) AND
((IIf([Forms]![CalendarExport]![Vendor] Is Not
Null,[Vendor]=[Forms]![CalendarExport]![Vendor],[Vendor] Is Not
Null))<>False) AND ((IIf([Forms]![CalendarExport]![Activity] Is Not
Null,[Activity]=[Forms]![CalendarExport]![Activity],[Activity] Is Not
Null))<>False) AND ((IIf([Forms]![CalendarExport]![Salesperson] Is Not
Null,[Salesperson]=[Forms]![CalendarExport]![Salesperson],[Salesperson] Is
Not Null))<>False))
ORDER BY [Master Planned].Date;
 
R

Rob Oldfield

Damn. This time I'm going to get it right.

Dim oDataBase As DAO.Database
Dim rst As DAO.Recordset
Set oDataBase = CurrentDb

Dim prm As Parameter
Dim qdf As QueryDef
Set qdf = oDataBase .QueryDefs("CalendarExport Q")
For Each prm In qdf.Parameters
prm.Value = Eval(prm.Name)
Next
Set rst = qdf.openrecordset
...do work
rst.close
set oDataBase =nothing




Rob Oldfield said:
No problem. I hope you realised that I completely screwed the last post and
included repetitions. Should be:

Dim oDataBase As DAO.Database
Dim rst As DAO.Recordset
Set oDataBase = CurrentDb

Dim prm As Parameter
Dim qdf As QueryDef
Set qdf = db.QueryDefs("CalendarExport Q")
For Each prm In qdf.Parameters
prm.Value = Eval(prm.Name)
Next
Set rst = qdf.openrecordset
...do work
rst.close
set db=nothing



Ben Adams said:
Worked Great!

Thanks Much!

Ben
"Too
Few
parameters. Expected 3." How can I have it call the records that show
when I
open the query?

Function ExportCalendartoOutlook()

Dim oDataBase As DAO.Database
Dim rst As DAO.Recordset
Set oDataBase = CurrentDb
Set rst = oDataBase.OpenRecordset("CalendarExport Q")

More code here, doesn't matter.....

End Function


CalendarExport Q

SELECT [Master Planned].Date, [Activity] & " / " & [Vendor] & " / " &
[Customer Forecasts]!Name AS Subject, [Master Planned].Comments AS Body,
"Sales Plan" AS Category
FROM [Branch Master] LEFT JOIN ([Customer Forecasts] RIGHT JOIN [Master
Planned] ON [Customer Forecasts].[Customer ID] = [Master
Planned].[Customer
ID]) ON [Branch Master].[Branch ID] = [Master Planned].[Branch ID]
WHERE ((([Master Planned].Date) Is Not Null) AND
((IIf([Forms]![CalendarExport]![Vendor] Is Not
Null,[Vendor]=[Forms]![CalendarExport]![Vendor],[Vendor] Is Not
Null))<>False) AND ((IIf([Forms]![CalendarExport]![Activity] Is Not
Null,[Activity]=[Forms]![CalendarExport]![Activity],[Activity] Is Not
Null))<>False) AND ((IIf([Forms]![CalendarExport]![Salesperson] Is Not
Null,[Salesperson]=[Forms]![CalendarExport]![Salesperson],[Salesperson] Is
Not Null))<>False))
ORDER BY [Master Planned].Date;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top