473,386 Members | 1,864 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.

Problem with the Form TextBox value format

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.

Expand|Select|Wrap|Line Numbers
  1.  
  2. Dim ValArrayDyn_B(2, 8) As Double
  3. Dim ValArrayDyn_C(2, 8) As Double
  4.  
  5. For i = 1 To 2
  6. For k = 1 To 8
  7.  
  8.  
  9. ValArrayDyn_B(i, k) = ([Forms]![frmLloydsViewsDyn3MTab1]![ValBS" & i & "C" & k & "_B])
  10. Debug.Print "ArrayValue", ValArrayDyn_B(i, k)
  11. ValArrayDyn_C(i, k) = ([Forms]![frmLloydsViewsDyn3MTab1]![ValBS" & i & "C" & k & "_C])
  12. Debug.Print "ArrayValue", ValArrayDyn_C(i, k)
  13.  
  14.  
  15. Next k
  16. Next i
  17.  
  18.  
Jul 1 '10 #1

✓ answered by MikeTheBike

@mabrynda
Hi

You could try something like this
Expand|Select|Wrap|Line Numbers
  1. Dim ValArrayDyn_B(2, 8) As Double
  2. Dim ValArrayDyn_C(2, 8) As Double
  3.  
  4. For i = 1 To 2
  5.     For k = 1 To 8
  6.         ValArrayDyn_B(i, k) = Me.Controls("ValBS" & i & "C" & k & "_B")
  7.         Debug.Print "ArrayValue", ValArrayDyn_B(i, k)
  8.         ValArrayDyn_C(i, k) = Me.Controls("ValBS" & i & "C" & k & "_C")
  9.         Debug.Print "ArrayValue", ValArrayDyn_C(i, k)
  10.     Next k
  11. 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
MikeTheBike
639 Expert 512MB
@mabrynda
Hi

You could try something like this
Expand|Select|Wrap|Line Numbers
  1. Dim ValArrayDyn_B(2, 8) As Double
  2. Dim ValArrayDyn_C(2, 8) As Double
  3.  
  4. For i = 1 To 2
  5.     For k = 1 To 8
  6.         ValArrayDyn_B(i, k) = Me.Controls("ValBS" & i & "C" & k & "_B")
  7.         Debug.Print "ArrayValue", ValArrayDyn_B(i, k)
  8.         ValArrayDyn_C(i, k) = Me.Controls("ValBS" & i & "C" & k & "_C")
  9.         Debug.Print "ArrayValue", ValArrayDyn_C(i, k)
  10.     Next k
  11. 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
Jul 1 '10 #2
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
Jul 1 '10 #3
NeoPa
32,556 Expert Mod 16PB
Here's an alternative. Not better necessarily, but illustrates an alternative approach :
Expand|Select|Wrap|Line Numbers
  1. Dim intI As Integer, intJ As Integer
  2. Dim ctl As Control
  3. Dim ValArrayDyn_B(2, 8) As Double 
  4. Dim ValArrayDyn_C(2, 8) As Double
  5.  
  6. For Each ctl In Me.Controls
  7.     With ctl
  8.         If .ControlType = acTextBox _
  9.         And Left(.Name, 5) = "ValBS" Then
  10.             intI = Val(Mid(.Name, 6, 1))
  11.             intJ = Val(Mid(.Name, 8, 1))
  12.             If Right(.Name, 2) = "_B" Then
  13.                 ValArrayDyn_B(intI, intK) = .Value
  14.             Else
  15.                 ValArrayDyn_C(intI, intK) = .Value
  16.             End If
  17.         End If
  18.     End With
  19. Next ctl
Jul 1 '10 #4
@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.
Jul 1 '10 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

3
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...
8
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...
1
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....
2
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...
2
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...
15
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...
3
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...
2
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...
10
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...
2
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...
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: 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
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.