473,399 Members | 2,146 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,399 software developers and data experts.

Recordset & Variables

doma23
107 100+
I have something like this:
Expand|Select|Wrap|Line Numbers
  1. Dim ctlName(5) As String
  2. Dim TableField(5) As String
  3.  
  4. ctlName(1) = "txtTextA"
  5. TableField(1) = "texta"
  6.  
  7. 'dim rs....
  8. 'dim cn...
  9.  
  10. rs.Open "tblTest", cn, adOpenDynamic, adLockOptimistic
  11. rs!TableField(1) = "Form_frmTest." & ctlName(1)
  12. rs.AddNew
  13.  
Obviously, this doesn't work (run-time error 3625; item cannot be found in the collection...), highlighted line is the one which I bolded.
Adding new records would go through the loop, this is just testing code.

Anybody knows if this is possible and if so, the right syntax?
Thank you!
Oct 25 '10 #1
2 1761
MikeTheBike
639 Expert 512MB
Hi

To get the code working I suggest this, assuming you are adding a new record as implied
Expand|Select|Wrap|Line Numbers
  1. Dim ctlName(5) As String 
  2. Dim TableField(5) As String 
  3.  
  4. ctlName(1) = "txtTextA" 
  5. TableField(1) = "texta" 
  6.  
  7. 'dim rs.... 
  8. 'dim cn... 
  9.  
  10. rs.Open "tblTest", cn, adOpenDynamic, adLockOptimistic 
  11. rs.AddNew 
  12. rs(1) = "Form_frmTest." & ctlName(1)
  13. rs.Update
Note; the recordset field collection is zero based, so the first field is accessed with rs(0) (or to be even more explicit rs.Fields(0)). Also, arrays are zero based unless specified otherwise (pardon the sermon if you already know this!).

HTH

MTB
Oct 25 '10 #2
doma23
107 100+
Hi, I don't think that will help me.
The problem is that I don't know when I will be adding new fields in the database and what the exact sequence of the fields will be.
So, what I want is when I add a new control on my form, I will just add a new field in the database and put the name of the control and name of the field in one module. And the writing procedure (adding data in the database through the loop) would remain the same.

So this:
rs!TableField(1) = "Form_frmTest." & ctlName(1)

Should represent this:
rs!txtTextA = (some value in textbox in Form_frmTest.txtTextA)
Oct 25 '10 #3

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

Similar topics

5
by: rwc | last post by:
I've got the following array I want to pass to smarty: a apple a artichoke b banana I want the output to look like: a 2 items apple articoke
3
by: Andie | last post by:
Hello All, How would I go about using a disconnect recordset and select (x) records from it, x being the number of records to be selected. Many thanks in advance. -- Andie
14
by: Rahul Chatterjee | last post by:
Hello All I have an asp page in which I am performing the following 1. Querying a database view 2. Returning rows in to a recordset. 3. Looping thru the recordset and printing the data 4....
3
by: HenryW | last post by:
I have a section of ASP code that dynamically builds a table. And per usual it writes out to the table like so: Response.Write("<td><font face=""Verdana"" size=""2""><b> Status...
11
by: Mr. Smith | last post by:
Hello all, My code can successfully open, write to, format and save several worksheets in a workbook then save it by a given name, close and quit excel. My problem is that if I try and do it...
3
by: Adam Knight | last post by:
Hi, Can I use variables declared in a code behind file in a .aspx file? If so, what needs to be done to make these variables available?
5
by: Simone M | last post by:
I would like to make a list of all the names of methods and variables in a cs file. I need to open up a file, create the list of all methods and properties, and variables, contained in that file,...
1
by: rlysaght | last post by:
I've got 20 pages that all have an identical code block that opens a db and assigns recordset to variables. Only difference is the product_id used in the query. I want to move this code to an...
2
Fary4u
by: Fary4u | last post by:
Hi i'm trying to make 2 different Connection & Recordset in 1 single file But accessing main values from the Query String, this part is working fine but only problem to access the 2nd part of...
2
by: shatemo5 | last post by:
Hi, I'm new in C++ programimng :( & I have a couple of questions to ask about :- 1- I have to build 5 clases & in each one I have to overide the opretaros new & delete ...so in each time I call...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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: 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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.