473,497 Members | 2,184 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Cycling through textboxes in a form

5 New Member
Hey everyone,
I'm having a little trouble figuring out how to do what I'm guessing is a simple procedure. I want to cycle through every textbox I have on a form and if the name of the textbox includes the word "Account" then I want to gather the information in that textbox. Unfourtunatly I can't figure out the base code for how to loop through all textboxes/comboboxes/checkboxes or anything. Any advice?
Oh, this is in access 2000 VBA on windows XP.
thanks.
Dec 27 '06 #1
14 3232
ADezii
8,834 Recognized Expert Expert
Hey everyone,
I'm having a little trouble figuring out how to do what I'm guessing is a simple procedure. I want to cycle through every textbox I have on a form and if the name of the textbox includes the word "Account" then I want to gather the information in that textbox. Unfourtunatly I can't figure out the base code for how to loop through all textboxes/comboboxes/checkboxes or anything. Any advice?
Oh, this is in access 2000 VBA on windows XP.
thanks.
Expand|Select|Wrap|Line Numbers
  1. Dim myCtl As Control
  2.  
  3. 'Loop through each Control in the Current Form
  4. For Each myCtl In Me.Controls
  5.   If myCtl.ControlType = acTextBox Then     'Control is a Text Box
  6.     If myCtl.Name Like "*" & "Account" & "*" Then   'Is the Name like *Account*
  7.       'Procesing code here
  8.     End If
  9.   End If
  10. Next
Dec 27 '06 #2
Killer42
8,435 Recognized Expert Expert
Hey everyone,
I'm having a little trouble figuring out how to do what I'm guessing is a simple procedure. I want to cycle through every textbox I have on a form and if the name of the textbox includes the word "Account" then I want to gather the information in that textbox. Unfourtunatly I can't figure out the base code for how to loop through all textboxes/comboboxes/checkboxes or anything. Any advice?
Oh, this is in access 2000 VBA on windows XP.
thanks.
This may need adjustment for Access, but in VB6 you could do something along these lines (untested)...
Expand|Select|Wrap|Line Numbers
  1. Dim ctl as Control
  2. Dim SearchFor As String
  3. SearchFor = "Account"
  4. For Each ctl In Me.Controls
  5.   If TypeOf ctl Is TextBox Then
  6.     If Instr(ctl.Name, SearchFor Then
  7.       ' Do your thing here.
  8.     End If
  9.   End If
  10. Next
  11.  
Dec 27 '06 #3
Killer42
8,435 Recognized Expert Expert
Expand|Select|Wrap|Line Numbers
  1. Dim myCtl As Control
  2. ...
  3.  
Damn, you beat me to it! :)

I really prefer the Instr( ) over Like, though. Makes for simpler code, in my opinion. But that's just personal preference, I guess.
Dec 27 '06 #4
missinglinq
3,532 Recognized Expert Specialist
And you forgot your closing parenthesis, Killer!

If Instr(ctl.Name, SearchFor) Then
Dec 27 '06 #5
willakawill
1,646 Top Contributor
Damn, you beat me to it! :)

I really prefer the Instr( ) over Like, though. Makes for simpler code, in my opinion. But that's just personal preference, I guess.
Ah yes, Killer. Always the bridesmaid, never the bride :)
Dec 27 '06 #6
missinglinq
3,532 Recognized Expert Specialist
But we know who gets the most action at the wedding, don't we Killer!
Dec 27 '06 #7
Killer42
8,435 Recognized Expert Expert
And you forgot your closing parenthesis, Killer!

If Instr(ctl.Name, SearchFor) Then
Oh, nuts! I'm usually on the lookout for that kind of detail. Of course, it's a lot easier to spot in someone else's code than your own.
Dec 27 '06 #8
Killer42
8,435 Recognized Expert Expert
But we know who gets the most action at the wedding, don't we Killer!
I'm not touching that one. :D
Dec 27 '06 #9
Lobster
5 New Member
This may need adjustment for Access, but in VB6 you could do something along these lines (untested)...
Expand|Select|Wrap|Line Numbers
  1. Dim ctl as Control
  2. Dim SearchFor As String
  3. SearchFor = "Account"
  4. For Each ctl In Me.Controls
  5.   If TypeOf ctl Is TextBox Then
  6.     If Instr(ctl.Name, SearchFor Then
  7.       ' Do your thing here.
  8.     End If
  9.   End If
  10. Next
  11.  
thanks alot, that got me going. My next question is, I have a loop going to gather info from all the combos on a form. I've got two columns of combo boxes, one column is all names of types of doughnuts. The second column is amounts of the doughnut that is in the combo box next to it. I've named each combo box in the columns either "cmbDoughnutName1" to "cmbDoughnutName12" or "cmbAmount1" to "cmbAmount12".

for k=1 to 12
'need code for here
next k

what I want in that spot is code that will grab the name and amount of the doughnut for each time it goes through the loop on the first time it would grab cmbDoughnutName1 and cmbAmount1. Do I need to loop through all the combo boxes each time to find the values or is there a way to find a combobox on a form with instr(combobox,"Amount"+str(k)) sort of thing quickly. Hope this makes sense.
thanks,
Lobster
Dec 28 '06 #10
Killer42
8,435 Recognized Expert Expert
Hi.

Sorry, I only have a moment (should be able to get back here tonight or tomorrow) but briefly, you'll find it a lot easier if you put the combo boxes in two control arrays. That way, rather than cmbDoughnutName1, cmbDoughnutName2 and so on, you can refer to cmbDoughnutName(number). It's much easier to work with an array.
Dec 28 '06 #11
NeoPa
32,556 Recognized Expert Moderator MVP
You could do a For Each ... Next for processing through them (ignore where name not Like "cmbDoughnut*") and build name of cmbAmount? from the Doughnut name.
This will avoid the necessity of building up the arrays outside of the loop.
Just a thought...
Dec 28 '06 #12
Killer42
8,435 Recognized Expert Expert
You could do a For Each ... Next for processing through them (ignore where name not Like "cmbDoughnut*") and build name of cmbAmount? from the Doughnut name.
This will avoid the necessity of building up the arrays outside of the loop.
Just a thought...
Sorry, I keep forgetting - Access doesn't do control arrays, does it?
Dec 29 '06 #13
willakawill
1,646 Top Contributor
Sorry, I keep forgetting - Access doesn't do control arrays, does it?
No but it can be simulated
Dec 29 '06 #14
Lobster
5 New Member
Thanks everyone, I think I got it. Take a five year break from programming and you forget the simplest things.
Dec 29 '06 #15

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

Similar topics

7
4059
by: Drew | last post by:
I have a db table like the following, UID, int auto-increment RegNo Person Relation YearsKnown Now here is some sample data from this table,
2
1439
by: Steveo | last post by:
Hi I have a form containing some text boxes and a button. I'm trying to work out how to make it so that if certain textboxes contain no data then the button is not enabled (however still...
3
1594
by: robbiehenry | last post by:
1. robbiehe...@gmail.com Sep 19, 1:48 pm show options From: robbiehe...@gmail.com - Find messages by this author Date: Mon, 19 Sep 2005 10:48:50 -0700 Local: Mon, Sep 19 2005 1:48 pm...
4
2800
by: Andy Weinmann | last post by:
I need to make a form through which I can edit the information for companies. I used a form in which the textboxes read from different columns from a listbox to display the information for a...
5
1541
by: -:= Cactus | last post by:
Hi! I've made a form for dataentry in a simple table. However when there are records in that table and I open the form it only displays the new (blank) record. The total number of records is 1,...
1
1724
by: Bernd Smits | last post by:
Hi, I've a form that is associated to a table, and a few textbox in it. Now when I compile all the textboxes (which each one corrispond to a field of the associated table), and I click on a button...
11
3094
by: ian.davies52 | last post by:
Is there anything I can do about the apparent limit on the number of textboxes that have calculations as their control source on a form or report in ms-access? I have a query that pulls together...
5
1688
by: BLACKDOG157 | last post by:
I've made a form with a variable number of textboxes. The user fills them out, and then I need to pick up the values he has filled in. The number of textboxes vary depending on a value that the...
2
4437
by: zufie | last post by:
I must combine the information from two forms/tabs on a main form. The idea is to insert two checkboxes on the main form. Then based on the checkbox checked would then automatically highlight...
0
7120
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
6991
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...
1
6878
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
7373
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
5456
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4897
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...
0
3088
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1405
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
286
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.