473,386 Members | 1,610 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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


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
8 1600
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
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
"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
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

"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
"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
"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
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Joshua Ammann | last post by:
Hi, (Using Access 2000) I have two tables, similar to Customers and Orders. (Not an exact parallel, but works for this example.) On a form showing customer data, there is a tab control. One...
1
by: Paul | last post by:
I have a MDI container form "frmParent". On that form there is a tabstrip control with 2 pages. On one of those pages there is a textbox and a button. When the user clicks on the button a...
1
by: Agnes | last post by:
in my tables, there are 20 fields, 15fields are bind to the textbox. however, some fields won't shown in the textbox , but I need to update it also. For example, i will increment the version ,...
6
by: Ludwig | last post by:
Hi, i'm using the regular expression \b\w to find the beginning of a word, in my C# application. If the word is 'public', for example, it works. However, if the word is '<public', it does not...
3
by: Miro | last post by:
First off...thanks in advance for getting me this far. Sorry for all these class posts but im having a heck of a time here trying to get something to work, and have finally got it to work (...
1
by: charmgirl | last post by:
hi, is it possible to have multple forms in a page. if yes than how to read data from multople forms ?
2
by: Ken Fine | last post by:
I want to add the security question and answer security feature to the ChangePassword control. I am aware that this functionality is built into the PasswordRecovery tool. I have implemented the...
4
by: phub11 | last post by:
Hi all, I have two pre-defined arrays; array1 = car, 1, tony; array2 = bus, 3, mike; I would like to make these into an arrayed array such that arrayFinal=tony. I've looked at...
5
by: KingKen | last post by:
I have a situation whereby I have to enter many records in a db that only have one field that changes. For example software installed on a computer would give you many different rows of data with...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.