Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Referring to objects with common pattern names...

Posted on 2002-05-28
5
Medium Priority
?
205 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 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

783 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