X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
   Reply to this topicStart new topic
> Variable Indirection, Access 2016    
post Aug 2 2019, 05:43 AM

Posts: 3
Joined: 6-August 13

Is there such a concept as indirection in VBA?

For example I have a variables V1,V2,V3 in an application

I want to be able to access these via a 4th variable vPointer as follow

vpointer = "V" & 1

then something like

Indirect(vpointer) = 10 ' this set V1 to a value of 10
or the other direction
debug.print indirect(vpointer) will print the value in V1, in this case 10.

I have come across this concept in several other programming languages but cannot find any references in an VBA resources that I have access to.

Just to forstall and suggestions of "Why not use an array?", v1,v2,v3 are controls on a form.
Go to the top of the page
post Aug 2 2019, 06:57 AM

UtterAccess VIP
Posts: 11,515
Joined: 6-December 03
From: Telegraph Hill

No, but if you have controls on a form named: "v1", "v2", "v3" you can use:
  Dim i As Integer

  For i = 1 to 3
    Debug.Print Me("v" & i)
  Next i



David Marten
Go to the top of the page
post Aug 2 2019, 07:41 AM

Posts: 1,003
Joined: 12-November 03
From: Iowa Lot

Would the eval() function do the trick? (probably not both ways)
This post has been edited by kfield7: Aug 2 2019, 07:42 AM
Go to the top of the page
Jeff B.
post Aug 2 2019, 08:57 AM

UtterAccess VIP
Posts: 10,300
Joined: 30-April 10
From: Pacific NorthWet

As David points out, you can still refer to the controls on the form via VBA. Are those controls bound or unbound? What is the desired result … that is, what will having the capability you seek then allow you to accomplish? (I ask because knowing where you want to get to may offer the opportunity for alternate routes)


Jeff Boyce
Microsoft Access MVP (2002-2015)

Mention of hardware or software is, in no way, an endorsement thereof. The FTC of the USA made this disclaimer necessary/possible.
Go to the top of the page

Custom Search

RSSSearch   Top   Lo-Fi    16th October 2019 - 12:04 AM