If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
Using a Variable to refer to a conrrol
I have four combo Boxes Box_1, Box_2, Box_3 and Box_4. I want to set the
default value to some data as part of the After_Update event. The cumbersome way to do it would be to have 4 individual sub routines to handle I want to do a whole host of other things that would be the same in each routine and a whole raft of code would be repeated for each Box Routine. I have tried setting up the following bit I can not get it to work, any help would be appreciated. Private Sub Box_1_AfterUpdate(NewData as String) Call BoxDefaultRoutine(NewData, 1) End Sub Rem This routine would be repeated for each of the other three boxes where the number 1 would be changed to number 2, 3, or 4 Private Sub BoxDefaultRoutine(NewData as string, BoxNumber) Dim BoxName as Control Rem Other bits of code BoxName = "Box_" & BoxNumber me.BoxName.DefaultValue - """" & newDAta & """" Rem More Code End Sub I have tried rapping BoxName in Parenthasis, tried seting it as a String and a number of other odd variations but to no avail. Sorry if my attempt to explain this is poor but I hope that you understand what I am trying to do. Thanks Ray C |
#2
|
|||
|
|||
Using a Variable to refer to a conrrol
You can use the controltype property of a control like:
Dim ctl As Control If ctl.ControlType = acComboBox Then or you can use something like an array of the names: Dim i As Integer Dim frm As Form Dim ctl As Control For i = 1 To 4 For each ctl in frm.Controls If ctl.Name = "Box_" & i Then -- Arvin Meyer, MCP, MVP http://www.datastrat.com http://www.mvps.org/access http://www.accessmvp.com "Ray C" wrote in message ... I have four combo Boxes Box_1, Box_2, Box_3 and Box_4. I want to set the default value to some data as part of the After_Update event. The cumbersome way to do it would be to have 4 individual sub routines to handle I want to do a whole host of other things that would be the same in each routine and a whole raft of code would be repeated for each Box Routine. I have tried setting up the following bit I can not get it to work, any help would be appreciated. Private Sub Box_1_AfterUpdate(NewData as String) Call BoxDefaultRoutine(NewData, 1) End Sub Rem This routine would be repeated for each of the other three boxes where the number 1 would be changed to number 2, 3, or 4 Private Sub BoxDefaultRoutine(NewData as string, BoxNumber) Dim BoxName as Control Rem Other bits of code BoxName = "Box_" & BoxNumber me.BoxName.DefaultValue - """" & newDAta & """" Rem More Code End Sub I have tried rapping BoxName in Parenthasis, tried seting it as a String and a number of other odd variations but to no avail. Sorry if my attempt to explain this is poor but I hope that you understand what I am trying to do. Thanks Ray C |
#3
|
|||
|
|||
Using a Variable to refer to a conrrol
Me.Controls("BoxName" & BoxNumber).DefaultValue = """" & newDAta & """"
-- Ken Snell MS ACCESS MVP http://www.accessmvp.com/KDSnell/ "Ray C" wrote in message ... I have four combo Boxes Box_1, Box_2, Box_3 and Box_4. I want to set the default value to some data as part of the After_Update event. The cumbersome way to do it would be to have 4 individual sub routines to handle I want to do a whole host of other things that would be the same in each routine and a whole raft of code would be repeated for each Box Routine. I have tried setting up the following bit I can not get it to work, any help would be appreciated. Private Sub Box_1_AfterUpdate(NewData as String) Call BoxDefaultRoutine(NewData, 1) End Sub Rem This routine would be repeated for each of the other three boxes where the number 1 would be changed to number 2, 3, or 4 Private Sub BoxDefaultRoutine(NewData as string, BoxNumber) Dim BoxName as Control Rem Other bits of code BoxName = "Box_" & BoxNumber me.BoxName.DefaultValue - """" & newDAta & """" Rem More Code End Sub I have tried rapping BoxName in Parenthasis, tried seting it as a String and a number of other odd variations but to no avail. Sorry if my attempt to explain this is poor but I hope that you understand what I am trying to do. Thanks Ray C |
Thread Tools | |
Display Modes | |
|
|