Solved

variable field name referencing

Posted on 1998-09-17
8
150 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 100 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

751 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