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 September 4th, 2010, 01:24 AM
Registered User
 
Join Date: Sep 2010
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Combining Variables to make a variable name

Hi,

I am new to VBA, so I apologize if this is too easy of a question. What I am trying to do is this.... I want var3 to return the expression "are really good" instead of returning the expression "Meatballs". How do you do this in VBA?

Code:
Dim Meatballs, var1, var2, var3 As String

Meatballs = "are really good"

var1 = "Meat"
var2 = "balls"

var3 = var1 & var2
 
Old September 4th, 2010, 04:03 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,093
Thanks: 1
Thanked 12 Times in 11 Posts
Default

Is this a trick question?

OK. I'll bite...

var3 = Meatballs
 
Old September 4th, 2010, 08:54 AM
Registered User
 
Join Date: Sep 2010
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

no, its not. i'm simplifying the situation. let me give you the real variables i am using, maybe this will help.

PYOY-1CurrMonth
PYOY-2CurrMnth
YOYLastMnth
YOYLastQtr
YOYCurrQtr = "[qtr]=2 and [fy] = 2009" (based on d look up to tblfsclcal)
YOYLastWk
PYOY-3LastMnth
etc,,,

I have all these variables defined as a Dlookup on a table I created called tblFiscalCalendar. This table defines the company's week #, qtr #, and month# for every day.

Based on user input, I am setting the three temp variables: var1, var2, and var3.

var1 = yoy or pyoy, pyoy-1, pyoy-2, pyoy-3, etc.
var2 = curr or prior
var3 = month or week or qtr or year


then for a 4th variable, I am combining all three

var 4 = var1& var2 & var3

so as an example, the output is "YOYCurrQtr".

But really what I want to be is "[qtr]=2 and [fy] = 2009"

(YOYCurrQtr is a variable i have defined above)
 
Old September 20th, 2010, 03:04 PM
Registered User
 
Join Date: Jun 2003
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Wink No pointers in VBA

It sounds like you're wanting to select a variable location by concatenating the values of multiple variables together and then use that product as the variable name whose value you need.

In C# you could use a pointer.

In VBA, I think you either have to use a CASE statement, a nested if, or an array. No pointers that I'm familiar with.

I can't think of ANY reason in Access that this would be necessary. I'm thinking you can maybe accomplish your goal with 1 query and a form tied to that query.

What is your goal? Maybe I can help achieve that without so much juggling of variables.

8^D





Similar Threads
Thread Thread Starter Forum Replies Last Post
Combining PHP and C++ Waffles C++ Programming 0 August 3rd, 2007 01:20 PM
Combining two Queries arholly Access 1 January 16th, 2007 06:40 PM
How to make a global variable? wavemehello Access VBA 2 February 14th, 2006 08:46 AM
A variable for variables John K. King VB How-To 9 November 6th, 2003 01:56 PM





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