473,382 Members | 1,252 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,382 software developers and data experts.

How to store recordset names in array?

what is wrong with this code?

Expand|Select|Wrap|Line Numbers
  1. Dim initials As String, e_SIG As String, queryFUP As String
  2. Dim rstFUP(4) As Recordset
  3.  
  4. Set rstMSG = CurrentDb.OpenRecordset("defaultemailmsg")
  5.  
  6. initials = "AM"
  7. e_SIG = vbCrLf & _
  8.         vbCrLf & _
  9.         vbCrLf & _
  10.         vbCrLf & _
  11.         "Kind regards," & vbCrLf & _
  12.         vbCrLf & _
  13.         "Awhi McLachlan" & vbCrLf & _
  14.         "AIMS Supporter Services/N.E.S.T." & vbCrLf & _
  15.         "Ph (09) 4376694"
  16.  
  17. For A = 1 To 4
  18. queryFUP = "followup_email" & A
  19. Set rstFUP(A) = CurrentDb.OpenRecordset(queryFUP)
  20. With rstFUP(A)
  21.     e_SUB = "Follow up on invitation to join Northland Electricity Emergency Helicopters Supporter Family"
  22.     .MoveFirst
  23.     Do Until .EOF
  24.         e_ADDY = !email
  25.         f_TYPE = (10 * !email_followup_type) + ![1stemailfeasturesize]
  26.         Select Case ![1stemailfeaturesize]
  27.  
  28. etc etc
  29.  
  30.  

the code errors at the set rstFUP(A) = ... line
it tells me "runtime error 3061, too few parameters. Expected 1"

why? can I not use an array in this way?
Feb 28 '11 #1

✓ answered by TheSmileyCoder

I honestly don't know whether or not its possible to make an array of recordsets.

Other options could include:
  1. Reuse the same variable:

    Expand|Select|Wrap|Line Numbers
    1. For A=1 to 4
    2.   queryFUP = "followup_email" & A
    3.   Set rstFUP = CurrentDb.OpenRecordset(queryFUP)
    4.   'etc...
    You would basicly just be updating its value each time.
  2. Use a collection instead of an array.
  3. Move the handling of the recordset to a seperate procedure that then gets called 4 times.

6 2819
pod
298 100+
Hi

difficult to evaluate based on the displayed code only ...

my suggestion is display in a message box (msgbox) your sql statement (queryFUP) before excuting it ... just to make certain it is a recognizable sql statement
Feb 28 '11 #2
TheSmileyCoder
2,322 Expert Mod 2GB
The code shows that queryfup is:
Expand|Select|Wrap|Line Numbers
  1. queryFUP = "followup_email" & A
However that will only work assuming that there is a query or a table called followup_email1 (or 2,3,4 as in example)
Feb 28 '11 #3
thanks for you reply. There are queries named "followup_email1", "...2",etc and they all execute properly when launched on their own.

If I replace the for next loop with and the rstFUP array with four individual variables and four separate subroutines for each query, the code works fine. Leads me to believe their is some issue with using an array to identify a recordset.
Feb 28 '11 #4
TheSmileyCoder
2,322 Expert Mod 2GB
I honestly don't know whether or not its possible to make an array of recordsets.

Other options could include:
  1. Reuse the same variable:

    Expand|Select|Wrap|Line Numbers
    1. For A=1 to 4
    2.   queryFUP = "followup_email" & A
    3.   Set rstFUP = CurrentDb.OpenRecordset(queryFUP)
    4.   'etc...
    You would basicly just be updating its value each time.
  2. Use a collection instead of an array.
  3. Move the handling of the recordset to a seperate procedure that then gets called 4 times.
Feb 28 '11 #5
Thanks Smiley, I like your option 3, great thinking. I will try to avoid arrayed recordsets in the future.
Feb 28 '11 #6
ADezii
8,834 Expert 8TB
@TheSmileyCoder - I wasn't actually sure myself, until now, but you can create an Array of Recordsets as in:
Expand|Select|Wrap|Line Numbers
  1. Dim MyDB As DAO.Database
  2. Dim rst1 As DAO.Recordset
  3. Dim rst2 As DAO.Recordset
  4. Dim rst3 As DAO.Recordset
  5.  
  6. Set MyDB = CurrentDb
  7.  
  8. Set rst1 = MyDB.OpenRecordset("SELECT * FROM [Order Details] WHERE [Quantity] = 1;", dbOpenSnapshot)
  9. Set rst2 = MyDB.OpenRecordset("SELECT * FROM [Order Details] WHERE [Quantity] = 10;", dbOpenSnapshot)
  10. Set rst3 = MyDB.OpenRecordset("SELECT * FROM [Order Details] WHERE [Quantity] = 100;", dbOpenSnapshot)
  11.  
  12. Dim aRecordsets(1 To 3) As DAO.Recordset
  13.  
  14. Set aRecordsets(1) = rst1
  15. Set aRecordsets(2) = rst2
  16. Set aRecordsets(3) = rst3
  17.  
  18. Debug.Print "Order ID", "Unit Price", "Quantity"
  19. Debug.Print "-------------------------------------------------"
  20.  
  21. With aRecordsets(3)
  22.   Do While Not .EOF
  23.     Debug.Print ![OrderID], Format$(![UnitPrice], "Currency"), ![Quantity]
  24.       .MoveNext
  25.   Loop
  26. End With
  27. Debug.Print "-------------------------------------------------"
  28.  
  29. aRecordsets(3).Close
  30. Set aRecordsets(3) = Nothing
OUTPUT (based on [Order details] Table of Northwind Sample Database):
Expand|Select|Wrap|Line Numbers
  1. Order ID      Unit Price    Quantity
  2. -------------------------------------------------
  3.  10286        $14.40         100 
  4.  10452        $15.50         100 
  5.  10549        $9.50          100 
  6.  10588        $14.00         100 
  7.  10607        $39.00         100 
  8.  10678        $38.00         100 
  9.  10854        $31.00         100 
  10.  10895        $34.00         100 
  11.  11030        $19.00         100 
  12.  11030        $55.00         100 
  13. -------------------------------------------------
  14.  
Mar 1 '11 #7

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

Similar topics

0
by: wASP | last post by:
I thought it was something relatively simple: ViewState = SomeObj; Then: SomeObj = ViewState; So, in my own code, I have this on the initial load:
4
by: Robert P. | last post by:
I can easily store a one-dimensional array in viewstate ( see Test1 ) If I try storing a multi-dimensional array in the viewstate it's crapping out on me when it goes to serialize the array (not...
0
by: Gert | last post by:
Hi, I need to store a array() of byte to a mysql field. I created a field in mysql of type varbinary. But storing and retrieving gives problems. Please help. The strTemp = EnDeCrypt(txt,...
4
by: Kev | last post by:
Hello, I have an Access 2003 database running on an XP network. I have a datasheet subform containing a 28 day roster - shift1 to shift28. Each record has 1 RosterEmpID, 1 EmployeeNumber, 28...
4
by: taquito | last post by:
Hi, a C newbie here. I have been reading threads here about reading txt files into array. I simply copied a couple of useful codes from here and modified to fit my situations. Then, I have two...
0
by: helm | last post by:
Folks, I have built a sailing race management system using Access 2002 and VB 6.3. I have results with which to determine placings in the various race series. In each series there are a number of...
1
by: radhikaullas | last post by:
Hello all In my application to store the encrypted password in sql server. i know the code for encrypt & decrypt. but the problem is the encrypt will return byte array. i dont know how to...
20
by: sruthini | last post by:
Hi, I am doing send some values(signup form::firstname,lastname,title,organization) to mail id using javamail at the same time it should store in database, my problem is how to fetch values from...
6
by: snsanju | last post by:
Hi, I am trying to write a program to fetch the HTML table values and store in the array as they are in the table. <table> <tr><td>value1</td><td>value2</td><td>value3</td></tr>...
13
by: tekinalp67 | last post by:
hi, i am trying to implement a B+ tree. There is no specification in the implementation so i am using arrays to implement the B+ tree. However, there is a problem that i encountered which is I...
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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.