By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,965 Members | 2,043 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,965 IT Pros & Developers. It's quick & easy.

Question 1: How to refer to a arrayed multple textbox?

P: n/a

Hi,

I am having two problems with Access 97. These '2 problems are posted
seperately in this newsgroup. Here's the first:

I have a form with lots of similar textboxes and I have a procedure that

acts on all these textboxes. Therefore I would like to refer to these
textboxes as an array.

My real form is somewhat more complicated, so for simplicity: Let's say
I
have a form with 5 textboxes who's name is "JanTextBox(1)" until
"JanTextBox(5)". I also have a button called "JanButton" and this button
has this code (on click):

Private Sub JanButton_Click()

Dim X As Integer

For X = 1 To 5
JanTextBox(X).Enabled = True
Next

End Sub

This yields the error : "Compile Error function or subfunction not
defined"
So it sees JanTextBox as a function. So I tell him this is an object.

Private Sub JanButton_Click()

Dim X As Integer
Dim JanTextBox(1 To 5) As TextBox

For X = 1 To 5
TextBox(Teller).Enabled = True
Next

End Sub

This is also not accepted: "Run time error '91':
Object variable or With block variable not set."
So does it want a 'set' statement? Let's try:

Private Sub JanButton_Click()

Dim X As Integer
Dim JanTextBox(1 To 5) As TextBox
Dim OtherBox As TextBox

For X = 1 To 5
Set OtherBox = JanTextBox(X)
OtherBox.Enabled = True
Next

End Sub

This gives the same result: "Run time error '91':
Object variable or With block variable not set."
It seems like Access doesn't want to recognize "JanTextBox(X)" as an
array
of textboxes.

How can I declare textboxes in an array like way?

Thanks: jan Veenstra
(For your information:

My initial solution however works but looks quite awkward
and I was trying to avoid this solution:
Renaming all JanTextBox(X) to JanTextBoxX:

Private Sub JanButton_Click()

JanTextBox1.Enabled = True
JanTextBox2.Enabled = True
JanTextBox3.Enabled = True
JanTextBox4.Enabled = True
JanTextBox5.Enabled = True

End Sub
)

--
..

Nov 13 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a
Try this:
Private Sub JanButton_Click()
Dim X As Integer
For X = 1 To 5
Me("JanTextBox" & X)..Enabled = True
Next
End Sub

Arno R

"jan Veenstra" <ve*********@hotmail.com> schreef in bericht news:42***************@hotmail.com...

Hi,

I am having two problems with Access 97. These '2 problems are posted
seperately in this newsgroup. Here's the first:

I have a form with lots of similar textboxes and I have a procedure that

acts on all these textboxes. Therefore I would like to refer to these
textboxes as an array.

My real form is somewhat more complicated, so for simplicity: Let's say
I
have a form with 5 textboxes who's name is "JanTextBox(1)" until
"JanTextBox(5)". I also have a button called "JanButton" and this button
has this code (on click):

Private Sub JanButton_Click()

Dim X As Integer

For X = 1 To 5
JanTextBox(X).Enabled = True
Next

End Sub

This yields the error : "Compile Error function or subfunction not
defined"
So it sees JanTextBox as a function. So I tell him this is an object.

Private Sub JanButton_Click()

Dim X As Integer
Dim JanTextBox(1 To 5) As TextBox

For X = 1 To 5
TextBox(Teller).Enabled = True
Next

End Sub

This is also not accepted: "Run time error '91':
Object variable or With block variable not set."
So does it want a 'set' statement? Let's try:

Private Sub JanButton_Click()

Dim X As Integer
Dim JanTextBox(1 To 5) As TextBox
Dim OtherBox As TextBox

For X = 1 To 5
Set OtherBox = JanTextBox(X)
OtherBox.Enabled = True
Next

End Sub

This gives the same result: "Run time error '91':
Object variable or With block variable not set."
It seems like Access doesn't want to recognize "JanTextBox(X)" as an
array
of textboxes.

How can I declare textboxes in an array like way?

Thanks: jan Veenstra


(For your information:

My initial solution however works but looks quite awkward
and I was trying to avoid this solution:
Renaming all JanTextBox(X) to JanTextBoxX:

Private Sub JanButton_Click()

JanTextBox1.Enabled = True
JanTextBox2.Enabled = True
JanTextBox3.Enabled = True
JanTextBox4.Enabled = True
JanTextBox5.Enabled = True

End Sub
)

--
.

Nov 13 '05 #2

P: n/a
Try this

Private Sub Command15_Click()
Dim cntl As Control
Dim iLoop As Byte
For Each cntl In Me.Controls
For iLoop = 1 To 5
If cntl.Name = "anTextBox" & CStr(iLoop) Then
Me(cntl.Name).Enabled = True
Next iLoop
Next cntl
End Sub
Filip
"jan Veenstra" <ve*********@hotmail.com> wrote in message
news:42***************@hotmail.com...

Hi,

I am having two problems with Access 97. These '2 problems are posted
seperately in this newsgroup. Here's the first:

I have a form with lots of similar textboxes and I have a procedure that

acts on all these textboxes. Therefore I would like to refer to these
textboxes as an array.

My real form is somewhat more complicated, so for simplicity: Let's say
I
have a form with 5 textboxes who's name is "JanTextBox(1)" until
"JanTextBox(5)". I also have a button called "JanButton" and this button
has this code (on click):

Private Sub JanButton_Click()

Dim X As Integer

For X = 1 To 5
JanTextBox(X).Enabled = True
Next

End Sub

This yields the error : "Compile Error function or subfunction not
defined"
So it sees JanTextBox as a function. So I tell him this is an object.

Private Sub JanButton_Click()

Dim X As Integer
Dim JanTextBox(1 To 5) As TextBox

For X = 1 To 5
TextBox(Teller).Enabled = True
Next

End Sub

This is also not accepted: "Run time error '91':
Object variable or With block variable not set."
So does it want a 'set' statement? Let's try:

Private Sub JanButton_Click()

Dim X As Integer
Dim JanTextBox(1 To 5) As TextBox
Dim OtherBox As TextBox

For X = 1 To 5
Set OtherBox = JanTextBox(X)
OtherBox.Enabled = True
Next

End Sub

This gives the same result: "Run time error '91':
Object variable or With block variable not set."
It seems like Access doesn't want to recognize "JanTextBox(X)" as an
array
of textboxes.

How can I declare textboxes in an array like way?

Thanks: jan Veenstra
(For your information:

My initial solution however works but looks quite awkward
and I was trying to avoid this solution:
Renaming all JanTextBox(X) to JanTextBoxX:

Private Sub JanButton_Click()

JanTextBox1.Enabled = True
JanTextBox2.Enabled = True
JanTextBox3.Enabled = True
JanTextBox4.Enabled = True
JanTextBox5.Enabled = True

End Sub
)

--
.

Nov 13 '05 #3

P: n/a
"Arno R" <ar***********@tiscali.nl> wrote in
news:42*********************@dreader2.news.tiscali .nl:
Private Sub JanButton_Click()
Dim X As Integer
For X = 1 To 5
Me("JanTextBox" & X)..Enabled = True
Next
End Sub


While that works because of implicit type coercion, I think it's
always best to explicity coerce numeric types to strings when you
know that's what you have. So, I would have this, instead:

Dim X As Integer
For X = 1 To 5
Me("JanTextBox" & CStr(X()).Enabled = True
Next

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Nov 13 '05 #4

P: n/a
Dim X As Integer
For X = 1 To 5
Me("JanTextBox" & CStr(X()).Enabled = True 'Errase the '(' after X
Next

"Filips Benoit" <be***********@pandora.be> wrote in message
news:G2**********************@phobos.telenet-ops.be...
Try this

Private Sub Command15_Click()
Dim cntl As Control
Dim iLoop As Byte
For Each cntl In Me.Controls
For iLoop = 1 To 5
If cntl.Name = "anTextBox" & CStr(iLoop) Then
Me(cntl.Name).Enabled = True
Next iLoop
Next cntl
End Sub
Filip
"jan Veenstra" <ve*********@hotmail.com> wrote in message
news:42***************@hotmail.com...

Hi,

I am having two problems with Access 97. These '2 problems are posted
seperately in this newsgroup. Here's the first:

I have a form with lots of similar textboxes and I have a procedure that

acts on all these textboxes. Therefore I would like to refer to these
textboxes as an array.

My real form is somewhat more complicated, so for simplicity: Let's say
I
have a form with 5 textboxes who's name is "JanTextBox(1)" until
"JanTextBox(5)". I also have a button called "JanButton" and this button
has this code (on click):

Private Sub JanButton_Click()

Dim X As Integer

For X = 1 To 5
JanTextBox(X).Enabled = True
Next

End Sub

This yields the error : "Compile Error function or subfunction not
defined"
So it sees JanTextBox as a function. So I tell him this is an object.

Private Sub JanButton_Click()

Dim X As Integer
Dim JanTextBox(1 To 5) As TextBox

For X = 1 To 5
TextBox(Teller).Enabled = True
Next

End Sub

This is also not accepted: "Run time error '91':
Object variable or With block variable not set."
So does it want a 'set' statement? Let's try:

Private Sub JanButton_Click()

Dim X As Integer
Dim JanTextBox(1 To 5) As TextBox
Dim OtherBox As TextBox

For X = 1 To 5
Set OtherBox = JanTextBox(X)
OtherBox.Enabled = True
Next

End Sub

This gives the same result: "Run time error '91':
Object variable or With block variable not set."
It seems like Access doesn't want to recognize "JanTextBox(X)" as an
array
of textboxes.

How can I declare textboxes in an array like way?

Thanks: jan Veenstra
(For your information:

My initial solution however works but looks quite awkward
and I was trying to avoid this solution:
Renaming all JanTextBox(X) to JanTextBoxX:

Private Sub JanButton_Click()

JanTextBox1.Enabled = True
JanTextBox2.Enabled = True
JanTextBox3.Enabled = True
JanTextBox4.Enabled = True
JanTextBox5.Enabled = True

End Sub
)

--
.


Nov 13 '05 #5

P: n/a

"David W. Fenton" <dX********@bway.net.invalid> schreef in bericht news:Xn**********************************@24.168.1 28.86...
"Arno R" <ar***********@tiscali.nl> wrote in
news:42*********************@dreader2.news.tiscali .nl:
Private Sub JanButton_Click()
Dim X As Integer
For X = 1 To 5
Me("JanTextBox" & X)..Enabled = True
Next
End Sub


While that works because of implicit type coercion, I think it's
always best to explicity coerce numeric types to strings when you
know that's what you have. So, I would have this, instead:

Dim X As Integer
For X = 1 To 5
Me("JanTextBox" & CStr(X()).Enabled = True
Next

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc


While my solution works and your solution won't ... ;-)
you are very right on the implicit vs. explicit issue.

You should have: Me("JanTextBox" & CStr(X)).Enabled = True

Arno R
Nov 13 '05 #6

P: n/a
"Arno R" <ar***********@tiscali.nl> wrote in
news:42*********************@dreader2.news.tiscali .nl:
"David W. Fenton" <dX********@bway.net.invalid> schreef in bericht
news:Xn**********************************@24.168.1 28.86...
"Arno R" <ar***********@tiscali.nl> wrote in
news:42*********************@dreader2.news.tiscali .nl:
Private Sub JanButton_Click()
Dim X As Integer
For X = 1 To 5
Me("JanTextBox" & X)..Enabled = True
Next
End Sub
While that works because of implicit type coercion, I think it's
always best to explicity coerce numeric types to strings when you
know that's what you have. So, I would have this, instead:

Dim X As Integer
For X = 1 To 5
Me("JanTextBox" & CStr(X()).Enabled = True
Next

--
David W. Fenton
http://www.bway.net/~dfenton dfenton at bway dot net
http://www.bway.net/~dfassoc


While my solution works and your solution won't ... ;-)
you are very right on the implicit vs. explicit issue.


Heh.
You should have: Me("JanTextBox" & CStr(X)).Enabled = True


That will teach me to post after coming back from the optometrist
after having my eyes dilated!

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Nov 13 '05 #7

P: n/a
"Filips Benoit" <be***********@pandora.be> wrote in
news:G2**********************@phobos.telenet-ops.be:
Private Sub Command15_Click()
Dim cntl As Control
Dim iLoop As Byte
For Each cntl In Me.Controls
For iLoop = 1 To 5
If cntl.Name = "anTextBox" & CStr(iLoop) Then
Me(cntl.Name).Enabled = True
Next iLoop
Next cntl
End Sub


This is the kind of thing that seems to me to call out for a custom
collection.

You'd assign control references to the collection in the form's
OnLoad event, then when you want to enable controls, you'd just loop
through the collection.

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Nov 13 '05 #8

P: n/a
"David W. Fenton" wrote:
"Arno R" <ar***********@tiscali.nl> wrote in
news:42*********************@dreader2.news.tiscali .nl:


Thanks guys. This really helped!

--
..

Nov 13 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.