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.
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.
- Dim myCtl As Control
-
-
'Loop through each Control in the Current Form
-
For Each myCtl In Me.Controls
-
If myCtl.ControlType = acTextBox Then 'Control is a Text Box
-
If myCtl.Name Like "*" & "Account" & "*" Then 'Is the Name like *Account*
-
'Procesing code here
-
End If
-
End If
-
Next
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)... -
Dim ctl as Control
-
Dim SearchFor As String
-
SearchFor = "Account"
-
For Each ctl In Me.Controls
-
If TypeOf ctl Is TextBox Then
-
If Instr(ctl.Name, SearchFor Then
-
' Do your thing here.
-
End If
-
End If
-
Next
-
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.
And you forgot your closing parenthesis, Killer!
If Instr(ctl.Name, SearchFor) Then
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 :)
But we know who gets the most action at the wedding, don't we Killer!
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.
But we know who gets the most action at the wedding, don't we Killer!
I'm not touching that one. :D
This may need adjustment for Access, but in VB6 you could do something along these lines (untested)... -
Dim ctl as Control
-
Dim SearchFor As String
-
SearchFor = "Account"
-
For Each ctl In Me.Controls
-
If TypeOf ctl Is TextBox Then
-
If Instr(ctl.Name, SearchFor Then
-
' Do your thing here.
-
End If
-
End If
-
Next
-
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
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.
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...
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?
Sorry, I keep forgetting - Access doesn't do control arrays, does it?
No but it can be simulated
Thanks everyone, I think I got it. Take a five year break from programming and you forget the simplest things.
Sign in to post your reply or Sign up for a free account.
Similar topics |
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,
|
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...
|
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...
|
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...
|
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,...
| |
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...
|
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...
|
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...
|
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...
|
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,...
|
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...
| |
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...
|
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...
|
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,...
|
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: 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...
|
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 ...
| |
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...
| |