enumerating through certain controls

G

Guest

i wish to deposit certain values in certain controls, basically this is a
form where a refund value is to be split up into its indivudal numbers (which
ive already got) and converted to english (which ive already done) and then
deposited into certain boxes, so that units are stored in the me![units],
tens in me![tens], hundreds in me![hundreds] etc.
I was looking to make a loop that stripped off the last number of the refund
value and deposited into the next box.
i am trying to use an array of controls to store the sequence of the
controls that i will need and then use the loop to move through this array
too.

Ive got something like this
Dim box As Integer
Dim boxNames(units, tens, Ctl100s, Ctl1000s) As Control

box = 0

'while there are still numbers left in the value
Do While Numbersize > 0
For box= 0 to boxname.length
'find the value of the last number
boxname(box) = ConvertDigit (Right(MyNumber))
'chop of that last number
MyNumber = Mid(MyNumber, 0, Numbersize - 1)
Next boxname
Loop

how do i form an array of controls as i need or this to work? it wont run
past that line of code!

with much appreciation for any help

Amit
 
D

Douglas J Steele

Access doesn't support control arrays. The closest you can get is to use a
naming convention for your controls (txt11, txt12, txt13, etc) and then
refer to the controls using Me.Controls("txt" & xvalue & yvalue)
 
G

Guest

can i pass an array of strings which hold the names of the text boxes and
then construct the textboxes that i want to insert into?

Ive tried to do this below but its throwing up and error that im still
looking at. I know its a little stupid but i dont want to go aroudn changing
my textbox names as iv got other calculations in this module which would need
altering! but ill change it if all else fails

Dim NumberSize As Integer
Dim box As Integer
Dim boxNames(4) As String
Dim TextControl As String

NumberSize = Len(refund)
box = 0

boxNames(0) = "units"
boxNames(1) = "tens"
boxNames(2) = "hundreds"
boxNames(3) = "thousands"

'while there are still numbers left in the value
Do While NumberSize > 0
'set the field to work with
TextControl = boxNames(box)
'find the value of the last number and put it into the field
Me(TextControl) = ConvertDigit(Right(refund))
'chop of that last number
refund = Mid(refund, 0, NumberSize - 1)
box 1
Loop





Access doesn't support control arrays. The closest you can get is to use a
naming convention for your controls (txt11, txt12, txt13, etc) and then
refer to the controls using Me.Controls("txt" & xvalue & yvalue)

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


DowningDevelopments said:
i wish to deposit certain values in certain controls, basically this is a
form where a refund value is to be split up into its indivudal numbers (which
ive already got) and converted to english (which ive already done) and then
deposited into certain boxes, so that units are stored in the me![units],
tens in me![tens], hundreds in me![hundreds] etc.
I was looking to make a loop that stripped off the last number of the refund
value and deposited into the next box.
i am trying to use an array of controls to store the sequence of the
controls that i will need and then use the loop to move through this array
too.

Ive got something like this
Dim box As Integer
Dim boxNames(units, tens, Ctl100s, Ctl1000s) As Control

box = 0

'while there are still numbers left in the value
Do While Numbersize > 0
For box= 0 to boxname.length
'find the value of the last number
boxname(box) = ConvertDigit (Right(MyNumber))
'chop of that last number
MyNumber = Mid(MyNumber, 0, Numbersize - 1)
Next boxname
Loop

how do i form an array of controls as i need or this to work? it wont run
past that line of code!

with much appreciation for any help

Amit
 
D

Douglas J. Steele

Try using Me.Controls(TextControl) rather than Me(TextControl)

I suspect that you meant box = box + 1, rather than box 1

I also don't see anything in your code that changes the value of NumberSize,
meaning that you've got an infinite loop there.

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


DowningDevelopments said:
can i pass an array of strings which hold the names of the text boxes and
then construct the textboxes that i want to insert into?

Ive tried to do this below but its throwing up and error that im still
looking at. I know its a little stupid but i dont want to go aroudn
changing
my textbox names as iv got other calculations in this module which would
need
altering! but ill change it if all else fails

Dim NumberSize As Integer
Dim box As Integer
Dim boxNames(4) As String
Dim TextControl As String

NumberSize = Len(refund)
box = 0

boxNames(0) = "units"
boxNames(1) = "tens"
boxNames(2) = "hundreds"
boxNames(3) = "thousands"

'while there are still numbers left in the value
Do While NumberSize > 0
'set the field to work with
TextControl = boxNames(box)
'find the value of the last number and put it into the field
Me(TextControl) = ConvertDigit(Right(refund))
'chop of that last number
refund = Mid(refund, 0, NumberSize - 1)
box 1
Loop





Access doesn't support control arrays. The closest you can get is to use
a
naming convention for your controls (txt11, txt12, txt13, etc) and then
refer to the controls using Me.Controls("txt" & xvalue & yvalue)

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


"DowningDevelopments" <[email protected]>
wrote
in message news:[email protected]...
i wish to deposit certain values in certain controls, basically this is
a
form where a refund value is to be split up into its indivudal numbers (which
ive already got) and converted to english (which ive already done) and then
deposited into certain boxes, so that units are stored in the
me![units],
tens in me![tens], hundreds in me![hundreds] etc.
I was looking to make a loop that stripped off the last number of the refund
value and deposited into the next box.
i am trying to use an array of controls to store the sequence of the
controls that i will need and then use the loop to move through this
array
too.

Ive got something like this
Dim box As Integer
Dim boxNames(units, tens, Ctl100s, Ctl1000s) As Control

box = 0

'while there are still numbers left in the value
Do While Numbersize > 0
For box= 0 to boxname.length
'find the value of the last number
boxname(box) = ConvertDigit (Right(MyNumber))
'chop of that last number
MyNumber = Mid(MyNumber, 0, Numbersize - 1)
Next boxname
Loop

how do i form an array of controls as i need or this to work? it wont
run
past that line of code!

with much appreciation for any help

Amit
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top