473,378 Members | 1,475 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Excel macro - error - too few parameters

Hello I am new to VBA and I am trying to create this program however I get the run time error 3061 Too few parameter expected_1, what does this mean, my code is:

Expand|Select|Wrap|Line Numbers
  1. Sub Template_Provider_Retail(Spinner As String)
  2.  
  3. Dim rs As Recordset
  4. Dim strSQL As String
  5. Dim i As Integer
  6. Dim IsSmall As Boolean
  7. Dim IsInsuf As Boolean
  8.  
  9. wbMaster.Worksheets("Provider_Retail").Copy After:=wbReport.Worksheets(wbReport.Worksheets.Count) 'copies the pages
  10.  
  11. strSQL = "Select Name, Retail_Credit_Index " & _
  12.             "FROM Retail_Credit_2007_Totals " & _
  13.             "WHERE Active = True " & _
  14.             "AND Name_2 = 'Total' " & _
  15.             "ORDER by Retail_Credit_Index Desc, Name Asc"
  16.  
  17. Set rs = db.OpenRecordset(strSQL)
  18.  
  19.  
  20.  With rs
  21.         If Not .BOF Then
  22.           .MoveLast   'Must do the movelast command to get the recordcount
  23.           .MoveFirst
  24.           Cells(14, 17).CopyFromRecordset rs, .RecordCount
  25.         End If
  26.  
  27.     End With
  28.  
  29. strSQL = "Select Name, Retail_Credit_Index " & _
  30.             "FROM Retail_Credit_2007 " & _
  31.             "WHERE Active = True " & _
  32.             "AND Name_2 = 'Total' " & _
  33.             "ORDER by Retail_Credit_Index Desc, Name Asc"
  34.  
  35. Set rs = db.OpenRecordset(strSQL)
  36.  
  37.  
  38.  With rs
  39.         If Not .BOF Then
  40.           .MoveLast   'Must do the movelast command to get the recordcount
  41.           .MoveFirst
  42.           Cells(14, 22).CopyFromRecordset rs, .RecordCount
  43.         End If
  44.  
  45.     End With
  46.  
  47.  
  48. strSQL = "Select Name, Retail_Credit_Index " & _
  49.             "FROM Retail_Credit_2006_Totals " & _
  50.             "WHERE Active = True " & _
  51.             "AND Name_2 = 'Total' " & _
  52.             "ORDER by Retail_Credit_Index Desc, Name Asc"
  53.  
  54. Set rs = db.OpenRecordset(strSQL)
  55.  
  56.  
  57.  With rs
  58.         If Not .BOF Then
  59.           .MoveLast   'Must do the movelast command to get the recordcount
  60.           .MoveFirst
  61.           Cells(26, 17).CopyFromRecordset rs, .RecordCount
  62.         End If
  63.  
  64.     End With
  65.  
  66.  
  67. strSQL = "Select Name, Retail_Credit_Index " & _
  68.             "FROM Retail_Credit_2006 " & _
  69.             "WHERE Active = True " & _
  70.             "AND Name_2 = 'Total' " & _
  71.             "ORDER by Retail_Credit_Index Desc, Name Asc"
  72.  
  73.  
  74. Set rs = db.OpenRecordset(strSQL)
  75.  
  76.  
  77.  With rs
  78.         If Not .BOF Then
  79.           .MoveLast   'Must do the movelast command to get the recordcount
  80.           .MoveFirst
  81.           Cells(26, 22).CopyFromRecordset rs, .RecordCount
  82.         End If
  83.  
  84.     End With
  85.  
  86. rs.Close
  87. Set rs = Nothing
  88.  
  89. Cells.Copy 'COPY ALL THE CELLS IN A WORKBOOK
  90. Cells.PasteSpecial xlPasteValues 'so it breaks the links

Can someone please HELP!!
Mar 26 '07 #1
7 2529
AricC
1,892 Expert 1GB
Hello I am new to VBA and I am trying to create this program however I get the run time error 3061 Too few parameter expected_1, what does this mean, my code is:

Sub Template_Provider_Retail(Spinner As String)

Dim rs As Recordset
Dim strSQL As String
Dim i As Integer
Dim IsSmall As Boolean
Dim IsInsuf As Boolean

wbMaster.Worksheets("Provider_Retail").Copy After:=wbReport.Worksheets(wbReport.Worksheets.Cou nt) 'copies the pages

strSQL = "Select Name, Retail_Credit_Index " & _
"FROM Retail_Credit_2007_Totals " & _
"WHERE Active = True " & _
"AND Name_2 = 'Total' " & _
"ORDER by Retail_Credit_Index Desc, Name Asc"

Set rs = db.OpenRecordset(strSQL)


With rs
If Not .BOF Then
.MoveLast 'Must do the movelast command to get the recordcount
.MoveFirst
Cells(14, 17).CopyFromRecordset rs, .RecordCount
End If

End With

strSQL = "Select Name, Retail_Credit_Index " & _
"FROM Retail_Credit_2007 " & _
"WHERE Active = True " & _
"AND Name_2 = 'Total' " & _
"ORDER by Retail_Credit_Index Desc, Name Asc"

Set rs = db.OpenRecordset(strSQL)


With rs
If Not .BOF Then
.MoveLast 'Must do the movelast command to get the recordcount
.MoveFirst
Cells(14, 22).CopyFromRecordset rs, .RecordCount
End If

End With


strSQL = "Select Name, Retail_Credit_Index " & _
"FROM Retail_Credit_2006_Totals " & _
"WHERE Active = True " & _
"AND Name_2 = 'Total' " & _
"ORDER by Retail_Credit_Index Desc, Name Asc"

Set rs = db.OpenRecordset(strSQL)


With rs
If Not .BOF Then
.MoveLast 'Must do the movelast command to get the recordcount
.MoveFirst
Cells(26, 17).CopyFromRecordset rs, .RecordCount
End If

End With


strSQL = "Select Name, Retail_Credit_Index " & _
"FROM Retail_Credit_2006 " & _
"WHERE Active = True " & _
"AND Name_2 = 'Total' " & _
"ORDER by Retail_Credit_Index Desc, Name Asc"


Set rs = db.OpenRecordset(strSQL)


With rs
If Not .BOF Then
.MoveLast 'Must do the movelast command to get the recordcount
.MoveFirst
Cells(26, 22).CopyFromRecordset rs, .RecordCount
End If

End With

rs.Close
Set rs = Nothing

Cells.Copy 'COPY ALL THE CELLS IN A WORKBOOK
Cells.PasteSpecial xlPasteValues 'so it breaks the links


Can someone please HELP!!
The Sub is expecting you to pass Spinner (a string variable) I don't think you are passing any values.
Mar 27 '07 #2
Killer42
8,435 Expert 8TB
Yes, AricC is probably right. If not, please provide more specific information about where the error occurs.
Mar 27 '07 #3
Yes, AricC is probably right. If not, please provide more specific information about where the error occurs.

I thought that the defined strSQL is passing a value each time it looks into the table and pulls the data that is requested and that is the value that is being passed the error occurs at the first Set rs = db.OpenRecordset(strSQL), however before each of those statements the database is return the values that it pulled from the database.......

I don't get it
Mar 27 '07 #4
SammyB
807 Expert 512MB
What we need to know is what line of code gives the error message. When Excel gives an error message, it also hylights a line of code that caused the error. Which line is it?
Mar 27 '07 #5
What we need to know is what line of code gives the error message. When Excel gives an error message, it also hylights a line of code that caused the error. Which line is it?

When I compile this code the run time error appears when I click debug it hightlight in yellow the first Set rs = db.OpenRecordset(strSQL)
Mar 27 '07 #6
SammyB
807 Expert 512MB
When I compile this code the run time error appears when I click debug it hightlight in yellow the first Set rs = db.OpenRecordset(strSQL)
Well, I'm a little flummoxed. What reference did you add, so that objects like Recordset were defined?

Also, do this so we have more information:
  1. In the VBE IDE, right-click on the menubar and choose Customize
  2. Select the Commands Tab
  3. Select the Debug Category
  4. Drag the compile project button up to the toolbar and drop it next to the run
  5. Close
  6. Press the Compile Project Button
  7. Do you get any error messages
Finally, db is not defined in your Sub, is it a global? How is it defined?
Thanks! --Sam
Mar 27 '07 #7
Killer42
8,435 Expert 8TB
When I compile this code the run time error appears when I click debug it hightlight in yellow the first Set rs = db.OpenRecordset(strSQL)
Well, at a simple level, this is just telling you that you've left out one or more parameters of the OpenRecordset method. It shouldn't be hard to check the syntax and see what parameters are required.

The contents of strSQL are irrelevant at this point - it is a string, and that's all you need to know here. So you have provided one string parameter - what else is required? In fact, depending on your settings, as soon as you type the "(" VBA should show you the parameter list.
Mar 27 '07 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: geronimo_me | last post by:
Hi, I am trying to run an Excel macro from an Access module, however when I run the code the macro runs but then I get an error in Access. The error is: Run-time error "440", Automation error. ...
3
by: bwhite | last post by:
I have a temp table with one row of data that I need to export into Excel. I created the export to create the xls file as follows ... Dim FileName FileName = !! DoCmd.SetWarnings False...
14
by: pmud | last post by:
Hi, I need to use an Excel Sheet in ASP.NET application so that the users can enter (copy, paste ) large number of rows in this Excel Sheet. Also, Whatever the USER ENETRS needs to go to the...
2
by: Aaron | last post by:
I am trying to design an application in Visual Studio that will allow a user to select a spreadsheet, pass in some parameters, and run macros in the spreadsheet that depend on the parameters. I was...
3
by: Mr.Doubt | last post by:
I'm trying to run a Excel macro, which uses SOLVER.XLA Add-In, in VB.NET application. When the macro is executed I get the following error message "Solver: An unexpected internal error occured,...
7
by: Alan Roberts | last post by:
Can someone please explain the following for me... I am trying to link to a .NET DLL from Excel. Excel needs to pass a reference to itself to the DLL and then the DLL needs to perform some work...
2
by: John Walker | last post by:
Hello, Below is my code for exporting a datagrid to Excel. It works fine, but we're hoping to format the output as well - setting the font size and type, and giving each column a specific width,...
7
by: Holger Fitschen | last post by:
Hi to all, I want to use the Excel solver in a VB.Net project. The macro Sub Makro1Solver() Application.Run "Solver.xla!Auto_Open" SolverReset Worksheets(1).Select...
7
by: NeverLift | last post by:
This is probably answered elsewhere, but I've searched the Web and VBA for Excel manual, find no answers. I have a VBA-coded macro in an Excel workbook that is to open another existing workbook --...
2
by: Gary Dunne | last post by:
Hi All, I'm struggling to find the correct syntax for creating a Pivot table in an excel file via VB . Net 2005 The Excel help file is not particularly helpful where parameters are concerned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.