Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Referring to objects with common pattern names...

Posted on 2002-05-28
5
Medium Priority
?
197 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 143

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 70

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 150 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…
Suggested Courses

661 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