Solved

Referring to objects with common pattern names...

Posted on 2002-05-28
5
160 Views
Last Modified: 2010-05-02
Is there a shorter way of doing these? Here are just 2 of the if statements. Is there a way to concatenate the model number to form a text box name, combobox name etc etc?
--
If chk_16700B.Value = True Then
        model_num = "16700B"
        option_type = cmb_16700B.Value
        nummodelship = txt_S16700B.Text
        Call Shipment_Update(model_num, nummodelship, option_type)
End If
If chk_16701B.Value = True Then
        model_num = "16701B"
        nummodelship = txt_S16701B.Text
        nummodel = txt_B16701B.Text
        Call Shipment_Update(model_num, nummodelship, option_type)
End If
--

Please help. Thanks :)    
0
Comment
Question by:sueannaberry
5 Comments
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 7038754

First, use vbChecked rather than True if the chk_XXX are checkboxes....

Now, try this:

select case vbChecked
  case chk_16700B.Value
     model_num = "16700B"
   
  case chk_16701B.Value
     model_num = "16701B"

end select
if model_num <> empty then
  option_type = callbyname ( me, "cmb_" & model_num, vbGet )
  nummodelship = callbyname ( me, "txt_S" & model_num, vbGet )
  Call Shipment_Update(model_num, nummodelship, option_type)
end if


CHeers
0
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 7038761
use control arrays

If chk_16700B.Value = True Then
       model_num = "16700B"
       intIndice = 0
ElseIf chk_16701B.Value = True Then
       model_num = "16701B"
       intIndice = 0
End If

option_type = cmbType(intIndice).Value
nummodelship = txtShip(intIndice).Text
nummodel = txtModel(intIndice).Text

Call Shipment_Update(model_num, nummodelship, option_type)
0
 
LVL 43

Expert Comment

by:TimCottee
ID: 7038820
Control arrays would be better but you could do this:

If chk_16700B.Value = True Then
       model_num = "16700B"
End If
If chk_16701B.Value = True Then
       model_num = "16701B"
End If
option_type = Me.Controls("cmb_" & model_num).Value
nummodelship = Me.Controls("cmb_" & model_num).Text
Call Shipment_Update(model_num, nummodelship, option_type)
0
 
LVL 43

Accepted Solution

by:
TimCottee earned 50 total points
ID: 7038821
Sorry that should be:

If chk_16700B.Value = True Then
      model_num = "16700B"
End If
If chk_16701B.Value = True Then
      model_num = "16701B"
End If
option_type = Me.Controls("cmb_" & model_num).Value
nummodelship = Me.Controls("txt_" & model_num).Text
Call Shipment_Update(model_num, nummodelship, option_type)
0
 
LVL 3

Expert Comment

by:MCummings111400
ID: 7039634
USing a Control Array....

Create two control Arrays, One for the check boxes and one for the textboxes.
Use the Tag prioperty of the checkboxes to store the model number.
The Value property stores the Option_Type.
Make the indexs for the TextBoxes match their corresponding Check boxes and the following code will update your variables when the option button is clicked

Sub chkModel_Click(Index as Integer)
    Model_Num = chkModel(Index).Tag ' Stores Model Number
    Option_Type = chkModel(Index).Value
    NumModelShip = txtShip(Index).Text ' Same Indexes as Model
End Sub

Then in your original Code

Call Shipment_Update(model_num, nummodelship, option_type)
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now