Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old February 22nd, 2006, 01:32 PM
Authorized User
 
Join Date: Feb 2006
Location: Sacramento, CA, USA.
Posts: 33
Thanks: 0
Thanked 0 Times in 0 Posts
Default Loop through combo boxes

I have not used VBA for about a year so I am a little rusty. I have a form with 25 combo boxes (not my design) and I need to check each combo box to see if it is populated. Is there a way to iterate through the combo boxes, say in a loop? The problem I am having is I do not know how to change the combo box name (cmb1) to the next combo box (cmb2) for the next loop.

Scott
__________________
ScottP
Reply With Quote
  #2 (permalink)  
Old February 22nd, 2006, 04:19 PM
Friend of Wrox
 
Join Date: Dec 2005
Location: , , .
Posts: 142
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Loop through the controls on the form

ex:
for i = 0 to form.controls.count - 1
if form.controls(i).type = acComboBox
 'do stuff here
end if

Reply With Quote
  #3 (permalink)  
Old February 22nd, 2006, 07:53 PM
Authorized User
 
Join Date: Feb 2006
Location: Sacramento, CA, USA.
Posts: 33
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Kindler, I will see if I can get it to work.

Scott
Reply With Quote
  #4 (permalink)  
Old February 23rd, 2006, 05:11 PM
Authorized User
 
Join Date: Feb 2006
Location: Sacramento, CA, USA.
Posts: 33
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Kindler, I finally got it to work. I kept getting errors when using the "if form.controls(i).type = acComboBox then" statement. But knowing that it is the "controls" allowed me to figure it out.

The 25 combo boxes go from cmbCF1 to cmbCF25.

For i = 1 To 25
    If IsNull(Me.Controls("cmbCF" & i)) = False Then
        Ptotals = Ptotals + CFPoints
    End If
Next i

Thanks again.

Scott
Reply With Quote
  #5 (permalink)  
Old February 24th, 2006, 09:50 AM
Friend of Wrox
Points: 4,007, Level: 26
Points: 4,007, Level: 26 Points: 4,007, Level: 26 Points: 4,007, Level: 26
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Lansing, Michigan, USA.
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
Send a message via ICQ to SerranoG Send a message via AIM to SerranoG
Default

Say, I have found that to be a problem in the past as well. Access XP (2002) doesn't want to recognize the .Type method, that is, a statement like this always fails:

if form.controls(i).type = acComboBox

I get around it by placing a unique string in my controls of interest .Tag property and do use a loop, but I use the .Tag property instead of the .Type property to pinpoint my controls.

Why does Access XP not accept the .Type method?




Greg Serrano
Michigan Dept. of Environmental Quality, Air Quality Division
Reply With Quote
  #6 (permalink)  
Old February 24th, 2006, 12:06 PM
Friend of Wrox
 
Join Date: Dec 2005
Location: , , .
Posts: 142
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You've got me Serrano, I'm using Access 2k3 but on databases saved in the 2000/02 format. I had to loop through and check for acCheckBox types and it worked (if I remember right). I ended up scrapping the type check though (so maybe it didn't work? It was a few months ago I wrote the code for that function) and just did a name check against the value in a field.

Glad you were able to get it working Scooter.

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Combo Boxes nbuckwheat Access 1 January 15th, 2006 09:26 AM
3 combo boxes ttkt Beginning PHP 0 July 2nd, 2005 02:20 PM
Combo boxes socoolbrewster Access 1 March 4th, 2004 09:28 AM
Combo Boxes tjs206 VB Databases Basics 2 December 10th, 2003 05:20 PM
combo boxes damnnono_86 Access 2 October 15th, 2003 09:00 PM



All times are GMT -4. The time now is 09:13 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.