Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 20th, 2006, 03:58 AM
Registered User
 
Join Date: Nov 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to get Object property using EVAL()?

Can you figure out how to do this?

I want to get the value of an object property. The trick is that the name of the property to retrieve is stored in a table.

Here's how I've set it up:

I have a class module "objPerson" which has a property "FirstName".
I can type: objPerson.FirstName = "John Smith"
and then the statement: strFirstName = objPerson.FirstName
will correctly result in strFirstName = "John Smith"

So far, so good, right?

Next, in "MyTable" I have a field "MyField" which contains the text string "objPerson.FirstName"

I want to get the value of the item specified by the string in MyField. In other words, I want the program to determine the value of whatever object property that I have stored in MyField. In this case, I have opened the object objPerson and I want the program to give me the value of "objPerson.FirstName".

I've tried using Eval(), but so far it doesn't work:

  strFirstName = Eval(rst.Fields("MyField"))

The result is: "Error 2482: Microsoft Access can't find the name 'objTenant' you entered in the expression."



 
Old November 20th, 2006, 05:42 PM
Registered User
 
Join Date: Nov 2006
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to GolferGuy
Default

If it will always be the objPerson object that you are dealing with, then objPerson(MyField) should give you the first name if MyField contains "FirstName". But, if the objPerson is not always the object you are dealing with, then I'm thinking you are going to have to write a special function with a Select statement and a Case statement for each object you might be dealing with.

Vic
 
Old November 20th, 2006, 06:07 PM
Registered User
 
Join Date: Nov 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for your reply, Vic.

Yes, I will be using different objects. I think you are correct about the SELECT-CASE solution.

Here's what I have so far, but I get an error:

=== stub ===
' assume I have already extracted the name of the object and the property:
strObjectName = "objTenant"
strPropertyName = "FirstName"

Select Case strObjectName
 Case "objTenant"
    ' Prepare the object
    Dim objTenant As Tenant
    Set objTenant = New Tenant
    objTenant.Load (TenantID)

    ' the goal is to dynamically get the requested property, like this:
    Debug.print "name=" & objTenant.Properties(strPropertyName)

    ' for testing, this works:
    Debug.Print "name1=" & objTenant.FirstName
    ' ^ up to here it works. It correctly displays: Name1=Joe

    ' The following lines return an error: "Compile error: Method or data member not found"
    Debug.Print "name2=" & objTenant.Properties(strPropertyName)
    Debug.Print "name3=" & objTenant.Properties("FirstName")
    Debug.Print "name4=" & objTenant.Properties!FirstName
========

Any ideas anyone?






Similar Threads
Thread Thread Starter Forum Replies Last Post
ResponseText property of XMLHTTPRequest Object prashantshekhar BOOK: Beginning Ajax with ASP.NET 1 August 28th, 2009 07:28 AM
"Value2" property of Range object sektor Excel VBA 1 April 11th, 2008 03:28 AM
VB6, COM, Object doesn't support this property... thenoseknows Classic ASP Professional 1 July 12th, 2007 05:54 PM
object property name from variable augustwest General .NET 3 June 9th, 2004 12:11 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.