Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

variable field name referencing

Posted on 1998-09-17
8
Medium Priority
?
152 Views
Last Modified: 2010-04-30
i want to hold a field name in a variable, then write one
piece of code where i can reference the .text value of
the field hald in that variable, same as using the NAME_IN
function in SQL*FORMS.

is there a way to do this or is vb worse than i thought!
0
Comment
Question by:newlook
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 

Expert Comment

by:Saradhi
ID: 1435341
Well, its easy. You can use the type statement in VB which is much like a structure in C.

You can declare a new type as :

Type Employee
      No As Integer
      Text As String
      Address As String
       Phone As Long
End Type

When declared you can use it in your program as:

Sub Main()
      Dim MyRecord As Employee       'Declare variable as Employee type      
      MyRecord.No = 12003      
                  MyRecord.Text="Sara"
                  MyRecord.Address="B-dj,Wels Street,Badel"
End Sub


You can reference this variable wherever you like in your program with all its fields (ie..MyRecord.Text).


0
 

Author Comment

by:newlook
ID: 1435342
sorry, thats not what i meant.
I need to have (for example) 2 text boxes Text1, Text2

set variable = Text1
msgbox variable.text ' to show Text1.Text

set variable = Text2
msgbox variable.text ' to show Text2.Text
0
 
LVL 18

Expert Comment

by:deighton
ID: 1435343
This is what you want

Private Sub Command1_Click()

    Dim x As TextBox
   
    Set x = Text1
   
    MsgBox x.Text
   
    Set x = text2
   
    MsgBox x.Text
   
   
End Sub
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 18

Accepted Solution

by:
deighton earned 300 total points
ID: 1435344
This is what you want   I hope!

      Private Sub Command1_Click()

          Dim x As TextBox
           
          Set x = Text1
           
          MsgBox x.Text
           
          Set x = text2
           
          MsgBox x.Text
           
           
      End Sub
0
 

Expert Comment

by:ChasDevlin
ID: 1435345
Hello Mr Deighton!
0
 

Author Comment

by:newlook
ID: 1435346
thanks for your help. sadly, although it works with text boxes
(i used that as an easier example) i need to get it working on
listboxes!! (it doesnt like that)

thanks anyway
0
 
LVL 18

Expert Comment

by:deighton
ID: 1435347
WHAT DOESN'T WORK????

Please ask here if you need any specific info.

[Hallo Chas!]

Here is a list box example, i seem to be able to access the properties ok.


Private Sub Command1_Click()

    Dim X As ListBox

    Set X = List1
   
    MsgBox X.Name
    MsgBox X.List(0)
    MsgBox X.List(1)
   

End Sub
0
 

Author Comment

by:newlook
ID: 1435348
ooh i tried that and couldn't get it to work! will cut and
paste your code and let you know
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question