A Microsoft Office (Excel, Word) forum. OfficeFrustration

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.

Go Back   Home » OfficeFrustration forum » Microsoft Access » New Users
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Using a Variable to refer to a conrrol



 
 
Thread Tools Display Modes
  #1  
Old February 10th, 2009, 12:42 AM posted to microsoft.public.access.gettingstarted
Ray C
external usenet poster
 
Posts: 215
Default 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  
Old February 10th, 2009, 04:03 AM posted to microsoft.public.access.gettingstarted
Arvin Meyer [MVP][_2_]
external usenet poster
 
Posts: 2,310
Default 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  
Old February 10th, 2009, 04:04 AM posted to microsoft.public.access.gettingstarted
Ken Snell \(MVP\)
external usenet poster
 
Posts: 2,506
Default 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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 08:44 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.