Dear All,
I have the following problem. In a form, I have several text boxes, from which I have to collect the numerical values introduced by the user. I can do that assigning a variable to each text box and then typing many lines looking like:
Variable1 = ([Forms]![FormName]![txtBoxName1])
Variable2 = ([Forms]![FormName]![txtBoxName2])
Etc...
This works fine.
However, I would like to reduce the number of lines in my code and decided to use an array to stock this information, especially because the txtBox names are a logical sequence. Therefore I have a loop, in which I'm trying to fill the array with the numerical values obtained from the txtBoxes. The problem is that I can't find the appropriate format to express the txtBoxName by incrementing it with the increasing numbers (such as txtBoxName1, txtBoxName2, txtBoxName3, etc...). The expression Variable = ([Forms]![FormName]![txtBoxName]) doesn't seem to accept dynamic names within it. Anybody has an idea ho to resolve this problem?
Thank you in advance.
Marcin
Here is the code that gives me the error (the program does not recognize " & i & " as an incrementing variable, but rather takes it as full text. -
-
Dim ValArrayDyn_B(2, 8) As Double
-
Dim ValArrayDyn_C(2, 8) As Double
-
-
For i = 1 To 2
-
For k = 1 To 8
-
-
-
ValArrayDyn_B(i, k) = ([Forms]![frmLloydsViewsDyn3MTab1]![ValBS" & i & "C" & k & "_B])
-
Debug.Print "ArrayValue", ValArrayDyn_B(i, k)
-
ValArrayDyn_C(i, k) = ([Forms]![frmLloydsViewsDyn3MTab1]![ValBS" & i & "C" & k & "_C])
-
Debug.Print "ArrayValue", ValArrayDyn_C(i, k)
-
-
-
Next k
-
Next i
-
-
@mabrynda
Hi
You could try something like this - Dim ValArrayDyn_B(2, 8) As Double
-
Dim ValArrayDyn_C(2, 8) As Double
-
-
For i = 1 To 2
-
For k = 1 To 8
-
ValArrayDyn_B(i, k) = Me.Controls("ValBS" & i & "C" & k & "_B")
-
Debug.Print "ArrayValue", ValArrayDyn_B(i, k)
-
ValArrayDyn_C(i, k) = Me.Controls("ValBS" & i & "C" & k & "_C")
-
Debug.Print "ArrayValue", ValArrayDyn_C(i, k)
-
Next k
-
Next i
??
To use concatenation you must be assigning the result to a string, which in your case (as far as the interpreter is concerned) it isn’t.
However, the argument for the Controls collection object is a string, so this should work.
MTB
4 1909 @mabrynda
Hi
You could try something like this - Dim ValArrayDyn_B(2, 8) As Double
-
Dim ValArrayDyn_C(2, 8) As Double
-
-
For i = 1 To 2
-
For k = 1 To 8
-
ValArrayDyn_B(i, k) = Me.Controls("ValBS" & i & "C" & k & "_B")
-
Debug.Print "ArrayValue", ValArrayDyn_B(i, k)
-
ValArrayDyn_C(i, k) = Me.Controls("ValBS" & i & "C" & k & "_C")
-
Debug.Print "ArrayValue", ValArrayDyn_C(i, k)
-
Next k
-
Next i
??
To use concatenation you must be assigning the result to a string, which in your case (as far as the interpreter is concerned) it isn’t.
However, the argument for the Controls collection object is a string, so this should work.
MTB
Hi MTB,
Thanks so much!!! It works great. I didn't in fact realize I wasn't working with the string in this case.
Anyway, it shortens things a lot....
Marcin
NeoPa 32,556
Expert Mod 16PB
Here's an alternative. Not better necessarily, but illustrates an alternative approach : - Dim intI As Integer, intJ As Integer
-
Dim ctl As Control
-
Dim ValArrayDyn_B(2, 8) As Double
-
Dim ValArrayDyn_C(2, 8) As Double
-
-
For Each ctl In Me.Controls
-
With ctl
-
If .ControlType = acTextBox _
-
And Left(.Name, 5) = "ValBS" Then
-
intI = Val(Mid(.Name, 6, 1))
-
intJ = Val(Mid(.Name, 8, 1))
-
If Right(.Name, 2) = "_B" Then
-
ValArrayDyn_B(intI, intK) = .Value
-
Else
-
ValArrayDyn_C(intI, intK) = .Value
-
End If
-
End If
-
End With
-
Next ctl
@NeoPa
Dear NeoPa,
Thanks too for the alternative approach. There is still lot of things I need to learn in VBA, but slowly I'm approaching the level of expertise needed to work on my (mostly simple) projects.
Thanks again.
M.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: H Branyan |
last post by:
I need to format a textbox value a user enters. The user will enter 13
characters, and then I have to format them, preferably in the onBlur event,
to look like this:
XXXX-XX-XXX-XXXX
I found...
|
by: Zlatko Matiæ |
last post by:
There is a form (single form) and a combobox. I want that current record of
the form is adjusted according to selected value in the combobox. Cuurrent
record should be the same as the value in the...
|
by: nic |
last post by:
Hi,
I have a textbox value that I need to force (and format)
to be a numeric value. For example, I want to allow a
user to type 1000 or 1,000 or 1,000,000 but not something
that is not numberic....
|
by: Atreju |
last post by:
Ok I got form within a c sharp page.
Situation:
On the form I have a drop downliwst and a textbox, the dropdownlist is
populated with products and the textbox has a default vale of the product...
|
by: danparks |
last post by:
I understand how to use ASP to retrieve a value from a form textbox. I don't understand how to use ASP to fill in a value in a form textbox. I'm guessing that perhaps Response.Write can be used? If...
|
by: staeri |
last post by:
I'm looping through some textboxes to sum the values. If the value in
the textbox has a dot or a space as thousand separator the sum function
doesn't work.
Can someone help me to make it work...
|
by: RevUK |
last post by:
Hi,
I am trying to link a textbox value from an Access 97 form to a specific cell in Excel 97.
I have tried many different avenues with this but as of yet I am still stuck on how to achieve...
|
by: Archanak |
last post by:
Hi,
I have one common text box to get email id.
I have 2 forms and both form action connects to different programs.
I want to use this textbox value(i.e email id) only for both the forms.
How...
|
by: pt36 |
last post by:
Hi
I have a page with a form and a textbox.
before to submit the form I want to chek if the inserted value in the
textbox is already present in a database.
So I need to pass the textbox value...
|
by: digituf |
last post by:
may i know if in php i can assign the textbox value from the user input as variables and then display the result of in the same page.
assume, user insert the checkin and checkout date, then it...
|
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,...
|
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$) {
}
...
|
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...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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...
| |