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

Refer to a form control as a variable in a loop

I have a form with a lot of controls on it that will be used to update tables. The nature of the data is such that I will be running queries based on the control name.
Expand|Select|Wrap|Line Numbers
  1. sqlstr="insert into tblgames (score) values (me.pbScore1);"
  2. doCmd.runsql(sqlstr)
  3. "insert into tblgames (score) values (me.pbScore2);"
  4. doCmd.runsql(sqlstr)
  5. insert into tblgames (score) values (me.pbScore3) etc..
This may be a lack of experience thing but I would like to refer to the form control in a loop sort of like
Expand|Select|Wrap|Line Numbers
  1. for i= 1 to .. then
  2.   sqlstr="insert into tblgames (score) values (me.pbScore " & i & ");"
is there a way to do this without retyping the query everytime?
Sep 6 '08 #1
1 2129
Stewart Ross
2,545 Expert Mod 2GB
Yes there is, by adding the number to the name of the control similarly to what you showed in your post and using this full control name to refer to the value of a specific control in the controls collection. It's easier to do than to describe:

Expand|Select|Wrap|Line Numbers
  1. for I = 1 to N
  2.  SQLStr = "INSERT INTO tblgames (score) VALUES (" & me.controls("pbscore" & I) & ")"
  3.  DoCmd.RunSQL SQLStr
  4. next I
-Stewart
Sep 6 '08 #2

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

Similar topics

6
by: octagon | last post by:
Hi, I have a form with various types of control such as txtbox, combo box, listbox, subform and check box I am trying hard to write a code for a check box after check the box all the control in...
4
by: solar | last post by:
How to refer to a subform ? On my main form called FrmEmployees I have a button to open a report. I want to forbid opening the report in case the liters in the subform are 0. To this end I...
3
by: Joshua Ammann | last post by:
Hi, (Using Access 2000) I have two tables, similar to Customers and Orders. (Not an exact parallel, but works for this example.) On a form showing customer data, there is a tab control. One...
8
by: jan Veenstra | last post by:
Hi, I am having two problems with Access 97. These '2 problems are posted seperately in this newsgroup. Here's the first: I have a form with lots of similar textboxes and I have a procedure...
1
by: Jeff | last post by:
Hello All: I have recently upgraded to VB .Net 2003 from VB6 and am having a little trouble. I have a MDI parent form that has a frame on it with a list box on the frame. I open an MDI child...
2
by: GY2 | last post by:
How do I refer to controls by a string variable name instead of by integer item index? A form contains 7 rich textbox controls labeled rtb1-rtb7. In VB6 I could use the following code to loop...
10
by: Bill Nguyen | last post by:
I have several textbox controls in a form,. I name them txt1, txt2, ... txt10. How dow I refer to them in a loop to get the value in text proerty of each control? For x = 1 to 10 value =...
2
by: Mike | last post by:
Hello, Ok I have 2 classes in my project, one is the main form and one is a connection class, at a certain event on my main form a new instance is made of the connection class, and a reference...
11
by: Web Search Store | last post by:
Hello, I set up a web page with 2 user controls. In classic asp, the first one did all the declarations, and the second one used the values, and could reset it. In ASP.Net so far I can't...
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: 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
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: 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...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.