473,624 Members | 2,439 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Macro Substitution

I know FoxPro has excellent macro substitution but I am trying to find
through MS Access. Wondering if MS Access has Macro Substitution? I will
give you my basic example.

In FoxPro Language Code

For i = 1 to 5
strCmd = "Client" + Alltrim(Str(i)) + "=" + Alltrim(Str(i))
&strCmd && Client1 = 1
Next

that make to store the data into variables like Client1, Client2, Client3 and
so on

In MS Access Language Code

For i = 1 to 5
strCmd = "Client" & Alltrim(Str(i)) & "=" & Alltrim(Str(i))
Eval(strCmd) -----> Error
Next

Any idea how to store the data into the variables? Thank you
May 8 '06 #1
7 6626
I would use an array for this. Check into the VBA help files for
arrays.

Jeremy
--
Jeremy Wallace
Fund for the City of New York
metrix.fcny.org

May 8 '06 #2
>Wondering if MS Access has Macro Substitution?

Look here:

http://groups.google.ca/group/comp.d...70a4d31ef5ef45

May 8 '06 #3
As others explained, VBA works quite differently than Fox/dBase.

If you are working with variables, an array makes sense. If you are actually
working with fields or controls on a form, you can refer to the Fields or
Controls collection using a string.

For example, if you had text boxes named Client1, Client2, ... Client5
(sounds very unnormalized, but lets use it as an example), you can code:

Dim strName as String
Dim i As Integer
For i = 1 to 5
strName = "Client" & i
Debug.Print Me.Controls(str Name )
Next

With a recordset, you can use:
rs.Fields(strNa me)

Since Controls is the default collection for a form, and Fields is the
default collection for a recordset, you can abreviate that to:
Me(strName )
rs(strName)

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"MtiPaulo" <u21659@uwe> wrote in message news:5ff596582a f69@uwe...
I know FoxPro has excellent macro substitution but I am trying to find
through MS Access. Wondering if MS Access has Macro Substitution? I
will
give you my basic example.

In FoxPro Language Code

For i = 1 to 5
strCmd = "Client" + Alltrim(Str(i)) + "=" + Alltrim(Str(i))
&strCmd && Client1 = 1
Next

that make to store the data into variables like Client1, Client2, Client3
and
so on

In MS Access Language Code

For i = 1 to 5
strCmd = "Client" & Alltrim(Str(i)) & "=" & Alltrim(Str(i))
Eval(strCmd) -----> Error
Next

Any idea how to store the data into the variables? Thank you

May 10 '06 #4
This code is kinda of "hardcode" but I want "flexible" code

intArgCount = 1
Do While True
strClientNo = Trim(GetSubStri ng(Me.OpenArgs, intArgCount, ";")) -----
Return "472"
If strClientNo <> "" Then
Select Case intArgCount
Case 1
Me.lblClient1.C aption = strClientNo
Case 2
Me.lblClient2.C aption = strClientNo
Case 3
Me.lblClient3.C aption = strClientNo
Case 4
Me.lblClient4.C aption = strClientNo
Case 5
Me.lblClient5.C aption = strClientNo
End Select
End If
intArgCount = intArgCount + 1
Loop

I just want to have "flexible" code like this:

intArgCount = 1
Do While True
strClientNo = Trim(GetSubStri ng(Me.OpenArgs, intArgCount, ";")) ---
Return "472"
If strClientNo <> "" Then
GetArgString = "lblClient" & Trim(Str(intArg Count )) & ".Caption"
Me.Controls(Get ArgString) = strClientNo ----- Error
End If
intArgCount = intArgCount + 1
Loop

I hope it helps!

Allen Browne wrote:
As others explained, VBA works quite differently than Fox/dBase.

If you are working with variables, an array makes sense. If you are actually
working with fields or controls on a form, you can refer to the Fields or
Controls collection using a string.

For example, if you had text boxes named Client1, Client2, ... Client5
(sounds very unnormalized, but lets use it as an example), you can code:

Dim strName as String
Dim i As Integer
For i = 1 to 5
strName = "Client" & i
Debug.Print Me.Controls(str Name )
Next

With a recordset, you can use:
rs.Fields(strNa me)

Since Controls is the default collection for a form, and Fields is the
default collection for a recordset, you can abreviate that to:
Me(strName )
rs(strName)
I know FoxPro has excellent macro substitution but I am trying to find
through MS Access. Wondering if MS Access has Macro Substitution? I

[quoted text clipped - 20 lines]

Any idea how to store the data into the variables? Thank you


--
Message posted via AccessMonster.c om
http://www.accessmonster.com/Uwe/For...ccess/200605/1
May 10 '06 #5
For i = 1 to 5
Me("lblClient" & i).Caption = strClientNo
Next

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"MtiPaulo via AccessMonster.c om" <u21659@uwe> wrote in message
news:5ffef69569 731@uwe...
This code is kinda of "hardcode" but I want "flexible" code

intArgCount = 1
Do While True
strClientNo = Trim(GetSubStri ng(Me.OpenArgs, intArgCount,
;")) -----
Return "472"
If strClientNo <> "" Then
Select Case intArgCount
Case 1
Me.lblClient1.C aption = strClientNo
Case 2
Me.lblClient2.C aption = strClientNo
Case 3
Me.lblClient3.C aption = strClientNo
Case 4
Me.lblClient4.C aption = strClientNo
Case 5
Me.lblClient5.C aption = strClientNo
End Select
End If
intArgCount = intArgCount + 1
Loop

I just want to have "flexible" code like this:

intArgCount = 1
Do While True
strClientNo = Trim(GetSubStri ng(Me.OpenArgs, intArgCount,
;")) ---
Return "472"
If strClientNo <> "" Then
GetArgString = "lblClient" & Trim(Str(intArg Count )) &
".Caption"
Me.Controls(Get ArgString) = strClientNo ----- Error
End If
intArgCount = intArgCount + 1
Loop

I hope it helps!

Allen Browne wrote:
As others explained, VBA works quite differently than Fox/dBase.

If you are working with variables, an array makes sense. If you are
actually
working with fields or controls on a form, you can refer to the Fields or
Controls collection using a string.

For example, if you had text boxes named Client1, Client2, ... Client5
(sounds very unnormalized, but lets use it as an example), you can code:

Dim strName as String
Dim i As Integer
For i = 1 to 5
strName = "Client" & i
Debug.Print Me.Controls(str Name )
Next

With a recordset, you can use:
rs.Fields(strNa me)

Since Controls is the default collection for a form, and Fields is the
default collection for a recordset, you can abreviate that to:
Me(strName )
rs(strName)
I know FoxPro has excellent macro substitution but I am trying to find
through MS Access. Wondering if MS Access has Macro Substitution? I

[quoted text clipped - 20 lines]

Any idea how to store the data into the variables? Thank you

May 10 '06 #6
Thanks. It works. Wonder why it won't work like this....

strCmd = "lblClient" & i
Me(strCmd).Capt ion = strClientNo

Allen Browne wrote:
For i = 1 to 5
Me("lblClient" & i).Caption = strClientNo
Next
This code is kinda of "hardcode" but I want "flexible" code

[quoted text clipped - 67 lines]

Any idea how to store the data into the variables? Thank you


--
Message posted via http://www.accessmonster.com
May 10 '06 #7
"MtiPaulo via AccessMonster.c om" <u21659@uwe> wrote in message
news:5fffc67db8 585@uwe...
Thanks. It works. Wonder why it won't work like this....

strCmd = "lblClient" & i
Me(strCmd).Capt ion = strClientNo

That should work. You should get into the habit of using

Option Explicit
in ALL OF your modeules. While in the code editor, go tools-> options and
check

[x] require variable definidation

The above setting will NOT chagne exsitng code..but in the future, any time
you create a new form, or new code module, the compiler directive
"Option Explicit" will be placed in the code for you....

That way, you are foreced to declear viarles..and
compiler will catch many errors beofre you even run the code...

Does your code complile now? Perhaps you have antoher object, or control
called
strCmd?

If it is a short loop, you could post the code....

You might want to note that since everything in ms-access is a collection,
then you can use a string to reference forms, fields etc, and thus will
RARELY ever need (or miss) the old FoxPro concept of substitution.

I wrote FoxPro applications for a number of
years, and when I switched over to ms-access, I did NOT miss macro subs
since virtually everything in ms-access is a collection, and thus you can
generally use a string to reference those things that otherwise would need
macro
subs in Fox.

--
Albert D. Kallal (Access MVP)
Edmonton, Alberta Canada
pl************* ****@msn.com
http://www.members.shaw.ca/AlbertKallal

May 10 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1422
by: Les | last post by:
Is there any way to do something like macro substitution in VB, like in C++ or C or other languages? --------------= Posted using GrabIt =---------------- ------= Binary Usenet downloading made easy =--------- -= Get GrabIt for free from http://www.shemes.com/ =-
6
2246
by: Raghuveer Pallikonda | last post by:
Hi, I am trying to stub out debug log messages in my application, if the logging subsystem is not enabled.. For e.g a invocation #define LOGMSG !Logger::Enabled() ? false : Logger::LogMsg so that LOGMSG("Log Me\n"); will be a NO-OP if the Logger::Enabled() returns false, else the
8
5338
by: Siemel Naran | last post by:
#define EXPECT_ASSERT(x) { if (!x) expect_assert(localVariable, __FILE__, __LINE__, #x); } MSVC7 gives an error: "error C2014: preprocessor command must start as first nonwhite space".
1
1620
by: me | last post by:
Hi guys I want to insert a load of pieces of data into a map The map has an std::string representing a field name as the key, and the value is a struct with 2 members - the field length and a bool indicating whether the field is a special field or not. The struct representing the value has a constructor that takes a single parameter for the length, and defaults the boolean to false.
7
23536
by: Newbie_sw2003 | last post by:
Where should I use them? I am giving you my understandings. Please correct me if I am wrong: MACRO: e.g.:#define ref-name 99 The code is substituted by the MACRO ref-name. So no overhead. Execution is faster. Where will it be stotred?(Is it in bss/stack/?) FUNCTION:
14
2054
by: Malcolm | last post by:
Hi, I have the following which fails with "disagreement in number of macro arguments" when compiling with Imagecraft ICCAVR. Has anyone got any ideas - its not vital but would make the code a lot nicer to read: #define SET(x,y) (x |=(1<<y)) #define PIEZO PORTB,5
1
5429
by: Rodolfo | last post by:
Hello, there's another languages that can do a macro substitution, how can I do this in Csharp. This is an example of what I want to do Dataset ds = new Dataset; string a = "ds"; DataSet ds2 = &a;
4
6912
by: Don | last post by:
I think "macro substitution" is the correct term for what I want to do, but, to be sure, here is a description of what I'd like to know is possible: I want to be able to create a create an object of a type whose name is stored in a constant. For example: Const FORM_NAME_1 as String = "frmThisForm" Const FORM_NAME_2 as String = "frmThatForm"
3
2171
by: XHengDF | last post by:
recent days. i am confuse on the macros in boost. could anyone tell me the replacement rules of the macros in c++, or somelinks about the macros in boost thanks
37
8961
by: junky_fellow | last post by:
hi guys, Can you please suggest that in what cases should a macro be preferred over inline function and viceversa ? Is there any case where using a macro will be more efficient as compared to inline function ? thanks for any help in advance ...
0
8240
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8625
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8482
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7168
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6111
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5565
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4082
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4177
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2610
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.