Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

variable field name referencing

Posted on 1998-09-17
8
Medium Priority
?
153 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
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 Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…
Suggested Courses

916 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