Err 3061Too Few Parameters

J

Johnny Bright

Hi there!

I have looked through this group for others who have had the same problem
but to no avail. So....

I am trying to run the following code and get Error 3061 Too few Parameters,
Expected 3.

Private Sub Command42_Click()
Dim db As Database, rstQueryData As Recordset
Dim objExcel As Object, intRowCounter As Integer


Set db = CurrentDb

Set objExcel = CreateObject("excel.Application")
With objExcel
.Visible = True
.Workbooks.Add
Set rstQueryData = db.OpenRecordset("qryFindGH", dbOpenSnapshot)


intRowCounter = 0
Do Until rstQueryData.EOF

.Range("A2").offset(intRowCounter, 0) = rstQueryData![Vendor]
.Range("A2").offset(intRowCounter, 0) = rstQueryData![VendorNum]

intRowCounter = intRowCounter + 1

rstQueryData.MoveNext
Loop
End With

End Sub

Excel opens just fine, but with no data in it. When I go back to Access,
the error message is sitting there, laughing at me! :)

What am I doing wrong here?

J
 
K

Klatuu

The query you are using a the recordset has 3 fields that have criteria on
them and it can't find the references the criteria is looking for.
Open your query in design mode and see which fields have a criteria set. Be
sure it is something a query can find.

Try running the query by itself to see what happens.
 
J

Johnny Bright

Hey there!

Thanks for the answer! The query works just great on its own. In fact, the
query is the record source for a sub form on which the button is located.
The query is based on two fields with parameters, however one field takes a
between x and y parameter so I guess that makes up the 3. What happens is
the form and sub form open with the sub form displaying the data I want to
export. The button is on the main form so I tried inserting this:
Set rstQueryData = Forms!frmFinalData.Form!frmFinalData_sub.Recordset and
this still doesn't work!

Still not sure what's wrong with this.

Thanks again for your help!

John


--
www.brightfuture.ca/bright
My email address can be found on my site.


Klatuu said:
The query you are using a the recordset has 3 fields that have criteria on
them and it can't find the references the criteria is looking for.
Open your query in design mode and see which fields have a criteria set. Be
sure it is something a query can find.

Try running the query by itself to see what happens.

Johnny Bright said:
Hi there!

I have looked through this group for others who have had the same problem
but to no avail. So....

I am trying to run the following code and get Error 3061 Too few Parameters,
Expected 3.

Private Sub Command42_Click()
Dim db As Database, rstQueryData As Recordset
Dim objExcel As Object, intRowCounter As Integer


Set db = CurrentDb

Set objExcel = CreateObject("excel.Application")
With objExcel
.Visible = True
.Workbooks.Add
Set rstQueryData = db.OpenRecordset("qryFindGH", dbOpenSnapshot)


intRowCounter = 0
Do Until rstQueryData.EOF

.Range("A2").offset(intRowCounter, 0) = rstQueryData![Vendor]
.Range("A2").offset(intRowCounter, 0) = rstQueryData![VendorNum]

intRowCounter = intRowCounter + 1

rstQueryData.MoveNext
Loop
End With

End Sub

Excel opens just fine, but with no data in it. When I go back to Access,
the error message is sitting there, laughing at me! :)

What am I doing wrong here?

J
 
J

Johnny Bright

I tried a test query with no parameters and it worked great. I then threw a
parameter into my original query based on a text box on a form and that's
where the whole thing stops. Is it not possible to use reference such a
query in code? The form with the text box is open although it doesn't have
the focus. Maybe that sheds a little more light on things.
--
www.humberboats.ca
My email address can be found on my site.


Johnny Bright said:
Hey there!

Thanks for the answer! The query works just great on its own. In fact, the
query is the record source for a sub form on which the button is located.
The query is based on two fields with parameters, however one field takes a
between x and y parameter so I guess that makes up the 3. What happens is
the form and sub form open with the sub form displaying the data I want to
export. The button is on the main form so I tried inserting this:
Set rstQueryData = Forms!frmFinalData.Form!frmFinalData_sub.Recordset and
this still doesn't work!

Still not sure what's wrong with this.

Thanks again for your help!

John


--
www.brightfuture.ca/bright
My email address can be found on my site.


Klatuu said:
The query you are using a the recordset has 3 fields that have criteria on
them and it can't find the references the criteria is looking for.
Open your query in design mode and see which fields have a criteria set. Be
sure it is something a query can find.

Try running the query by itself to see what happens.

Johnny Bright said:
Hi there!

I have looked through this group for others who have had the same problem
but to no avail. So....

I am trying to run the following code and get Error 3061 Too few Parameters,
Expected 3.

Private Sub Command42_Click()
Dim db As Database, rstQueryData As Recordset
Dim objExcel As Object, intRowCounter As Integer


Set db = CurrentDb

Set objExcel = CreateObject("excel.Application")
With objExcel
.Visible = True
.Workbooks.Add
Set rstQueryData = db.OpenRecordset("qryFindGH", dbOpenSnapshot)


intRowCounter = 0
Do Until rstQueryData.EOF

.Range("A2").offset(intRowCounter, 0) = rstQueryData![Vendor]
.Range("A2").offset(intRowCounter, 0) = rstQueryData![VendorNum]

intRowCounter = intRowCounter + 1

rstQueryData.MoveNext
Loop
End With

End Sub

Excel opens just fine, but with no data in it. When I go back to Access,
the error message is sitting there, laughing at me! :)

What am I doing wrong here?

J
 
D

Douglas J. Steele

Forms!frmFinalData.Form!frmFinalData_sub.Recordset doesn't look like a
valid reference.

Assuming that your form is named frmFinalData, and the name of the control
on that form that contains the subform is frmFinalData_sub, try

Forms!frmFinalData!frmFinalData_sub.Form.Recordset

(Note that the name of the subform control on frmFinalData may not be the
same as the name of the form being used as the subform)

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Johnny Bright said:
I tried a test query with no parameters and it worked great. I then threw
a
parameter into my original query based on a text box on a form and that's
where the whole thing stops. Is it not possible to use reference such a
query in code? The form with the text box is open although it doesn't
have
the focus. Maybe that sheds a little more light on things.
--
www.humberboats.ca
My email address can be found on my site.


Johnny Bright said:
Hey there!

Thanks for the answer! The query works just great on its own. In fact,
the
query is the record source for a sub form on which the button is located.
The query is based on two fields with parameters, however one field takes
a
between x and y parameter so I guess that makes up the 3. What happens
is
the form and sub form open with the sub form displaying the data I want
to
export. The button is on the main form so I tried inserting this:
Set rstQueryData = Forms!frmFinalData.Form!frmFinalData_sub.Recordset and
this still doesn't work!

Still not sure what's wrong with this.

Thanks again for your help!

John


--
www.brightfuture.ca/bright
My email address can be found on my site.


Klatuu said:
The query you are using a the recordset has 3 fields that have criteria
on
them and it can't find the references the criteria is looking for.
Open your query in design mode and see which fields have a criteria
set. Be
sure it is something a query can find.

Try running the query by itself to see what happens.

:

Hi there!

I have looked through this group for others who have had the same
problem
but to no avail. So....

I am trying to run the following code and get Error 3061 Too few
Parameters,
Expected 3.

Private Sub Command42_Click()
Dim db As Database, rstQueryData As Recordset
Dim objExcel As Object, intRowCounter As Integer


Set db = CurrentDb

Set objExcel = CreateObject("excel.Application")
With objExcel
.Visible = True
.Workbooks.Add
Set rstQueryData = db.OpenRecordset("qryFindGH", dbOpenSnapshot)


intRowCounter = 0
Do Until rstQueryData.EOF

.Range("A2").offset(intRowCounter, 0) = rstQueryData![Vendor]
.Range("A2").offset(intRowCounter, 0) = rstQueryData![VendorNum]

intRowCounter = intRowCounter + 1

rstQueryData.MoveNext
Loop
End With

End Sub

Excel opens just fine, but with no data in it. When I go back to
Access,
the error message is sitting there, laughing at me! :)

What am I doing wrong here?

J
 
Top