Solved

Referring to objects with common pattern names...

Posted on 2002-05-28
5
175 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 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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

Suggested Solutions

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…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…

734 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