Solved

Referring to objects with common pattern names...

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

772 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