473,322 Members | 1,736 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,322 software developers and data experts.

how to assign a field name from a String?

7
I have following code:
Expand|Select|Wrap|Line Numbers
  1. Dim TestData, Limits As Recordset
  2. Dim TestID As String
  3. TestID = Limits![Test].Value '"TestID" does contain the correct string value.
  4. MsgBox (TestData![TestID].Value)
line 4 does not work.need help...



Thanks!!
Oct 23 '08 #1
5 3940
GazMathias
228 Expert 128KB
Expand|Select|Wrap|Line Numbers
  1. 1    Dim TestData, Limits As Recordset
  2. 2    Dim TestID As String
  3. 3    TestID = Limits![Test].Value 
  4. "TestID" does contain the correct string value.
  5. 4    MsgBox (TestData![TestID].Value)
Is this seriously all of the code?
Oct 23 '08 #2
qwert1
7
just the part that matters.

Dim TestData, Limits As Recordset
Dim TestID As String
Dim Data As Integer

TestID = Limits![Test].Value

"TestID" contains the correct string value that represents the field name.

Now I am interested to know how can I get the value of that field. So I can do
Data = TestData![TestID].Value (This line does not work)
Oct 23 '08 #3
qwert1
7
I find out I can do it as following:
Expand|Select|Wrap|Line Numbers
  1. Data = TestData.Fields(TestID).Value
Oct 23 '08 #4
Stewart Ross
2,545 Expert Mod 2GB
Hi. That's correct, as specific fields in the Fields collection can be accessed by name (or by integer index number), whereas what you were trying before was incorrect -

TestData![TestID]

was trying to refer to a (non-existent) field called TestID (and not the value of the variable itself).

By the way, the Value property of a control is the default property which is obtained when the control is referenced - there is no need to specify this one explicitly, as

someform!somecontrol.value

has the same effect as

someform!somecontrol

-Stewart
Oct 24 '08 #5
qwert1
7
Hi. That's correct, as specific fields in the Fields collection can be accessed by name (or by integer index number), whereas what you were trying before was incorrect -

TestData![TestID]

was trying to refer to a (non-existent) field called TestID (and not the value of the variable itself).

By the way, the Value property of a control is the default property which is obtained when the control is referenced - there is no need to specify this one explicitly, as

someform!somecontrol.value

has the same effect as

someform!somecontrol

-Stewart
Thanks, Stewart...I appreciate your comments.
Oct 24 '08 #6

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

Similar topics

4
by: Eric | last post by:
How can I dynamically assign an event to an element? I have tried : (myelement is a text input) document.getElementById('myelement').onKeyUp = "myfnc(param1,param2,param3)"; ...
0
by: Steve | last post by:
I know this might not be the best place to get help for this particular problem, but here goes.. The 2nd edition of ProfessionalCrystal Reports for Visual Studio .NET states "you will learn how to...
1
by: gaffar | last post by:
Hello Sir, How to assign more than one primary key to table by this below following code. i am able assign to a single field only. how to assign primary key to more than one field. the primary key...
1
by: google | last post by:
It would seem that when I assign an HTML entity to a form text input using "inline" javascript that it will display properly. But when trying to set it via a function call, the entity text shows...
2
by: gaffar | last post by:
Hello Sir, How to assign more than one primary key to table by this below following code. i am able assign to a single field only. how to assign primary key to more than one field. the primary key...
1
by: Marc | last post by:
Hi! I'm working with a C# client that calls a php web service. I've created a wrapper to call the service using .NET wsdl tool (adding a web reference). The call to the server works fine, it...
6
by: david | last post by:
I try to use "for" loop to retrieve and assign values in web form. The code is in the following. But it can not be compiled. What I want to do is: txtQ1.Text =...
7
by: david | last post by:
I try to use "for" loop to assign textbox control ID to a textbox variable in server side codebehind for a web form. But I met some problem. What I want to do is solving the following-like code by...
4
by: Steve Goldman | last post by:
Even asking this question probably demonstrates that I have a fundamental misunderstanding of how values and references work in C#, but here goes: I'd like to assign a reference to an arbitrary...
1
by: Florian Paulus | last post by:
Hi group, i'm wondering how to assign an attribute to a field that a class inherited from a base class. Say base class has a field protected string message, so in the derived class i want to...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.