Solved

variable field name referencing

Posted on 1998-09-17
8
145 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
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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

910 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now