Naming Combo boxes

  • Thread starter auujxa2 via AccessMonster.com
  • Start date
A

auujxa2 via AccessMonster.com

I have to create MANY forms with MANY combo boxes. The strSQL behind the
scenes is going to be tedious enough, but...

Is there a way to name the boxes in a quick manner, systemically? (i.e. i
want the first row of 6 combos to be cbo1a, cbo1b, ===>cbo1f. Row 2 = cbo2a,
cbo2b, etc.)

But if I have 20+ rows, it's taking me a long time to name them.

Any ideas?
 
P

PieterLinden via AccessMonster.com

auujxa2 said:
I have to create MANY forms with MANY combo boxes. The strSQL behind the
scenes is going to be tedious enough, but...

Is there a way to name the boxes in a quick manner, systemically? (i.e. i
want the first row of 6 combos to be cbo1a, cbo1b, ===>cbo1f. Row 2 = cbo2a,
cbo2b, etc.)

But if I have 20+ rows, it's taking me a long time to name them.

Any ideas?

What is the purpose of this form? Changing the names of the comboboxes is
easy enough, but WHY? Please explain the purpose of your form. Maybe
there's a better way of accomplishing your goal than by doing this. (This is
where you come in and explain the business goal behind what you're trying to
do.) You can rename controls on the fly, if you want with code like this,
but I'm not convinced it is the best solution to your problem....

Option Compare Database
Option Explicit

Public Sub RenameCombosOnForm(strFormName As String)
'sample call: RenameCombosOnForm "frmRenameCombos"
Dim frm As Form
Dim ctl As Control
Dim intCounter As Integer

' Make a backup of the original form in case something goes horribly
wrong... <g>
DoCmd.CopyObject "", strFormName & "_BU", acForm, strFormName

' Open the form in design view (hidden)
DoCmd.OpenForm strFormName, acDesign, , , , acHidden

Set frm = Forms(strFormName)

' loop through the controls of the form
For Each ctl In frm.Controls
If TypeOf ctl Is ComboBox Then
intCounter = intCounter + 1
ctl.Name = "cbo" & intCounter
End If
Next ctl

DoCmd.Close acForm, frm.Name, acSaveYes

End Sub
 
A

auujxa2 via AccessMonster.com

I am recreating entry forms, so a company's technicians can go paperless.

So there's a lot of "YES";"NO";"NA" combos, or "PASS";"FAIL";"NA" combos.

But I want to specifically name the combos, so it's easier for me to refer to
them when I write the strSQL.

ie:
me.cbo1a.value
me.cbo1b.value
etc.
I have to create MANY forms with MANY combo boxes. The strSQL behind the
scenes is going to be tedious enough, but...
[quoted text clipped - 6 lines]
Any ideas?

What is the purpose of this form? Changing the names of the comboboxes is
easy enough, but WHY? Please explain the purpose of your form. Maybe
there's a better way of accomplishing your goal than by doing this. (This is
where you come in and explain the business goal behind what you're trying to
do.) You can rename controls on the fly, if you want with code like this,
but I'm not convinced it is the best solution to your problem....

Option Compare Database
Option Explicit

Public Sub RenameCombosOnForm(strFormName As String)
'sample call: RenameCombosOnForm "frmRenameCombos"
Dim frm As Form
Dim ctl As Control
Dim intCounter As Integer

' Make a backup of the original form in case something goes horribly
wrong... <g>
DoCmd.CopyObject "", strFormName & "_BU", acForm, strFormName

' Open the form in design view (hidden)
DoCmd.OpenForm strFormName, acDesign, , , , acHidden

Set frm = Forms(strFormName)

' loop through the controls of the form
For Each ctl In frm.Controls
If TypeOf ctl Is ComboBox Then
intCounter = intCounter + 1
ctl.Name = "cbo" & intCounter
End If
Next ctl

DoCmd.Close acForm, frm.Name, acSaveYes

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top