473,395 Members | 1,468 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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 6595
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(strName )
Next

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

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:5ff596582af69@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(GetSubString(Me.OpenArgs, intArgCount, ";")) -----
Return "472"
If strClientNo <> "" Then
Select Case intArgCount
Case 1
Me.lblClient1.Caption = strClientNo
Case 2
Me.lblClient2.Caption = strClientNo
Case 3
Me.lblClient3.Caption = strClientNo
Case 4
Me.lblClient4.Caption = strClientNo
Case 5
Me.lblClient5.Caption = 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(GetSubString(Me.OpenArgs, intArgCount, ";")) ---
Return "472"
If strClientNo <> "" Then
GetArgString = "lblClient" & Trim(Str(intArgCount )) & ".Caption"
Me.Controls(GetArgString) = 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(strName )
Next

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

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.com
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.com" <u21659@uwe> wrote in message
news:5ffef69569731@uwe...
This code is kinda of "hardcode" but I want "flexible" code

intArgCount = 1
Do While True
strClientNo = Trim(GetSubString(Me.OpenArgs, intArgCount,
;")) -----
Return "472"
If strClientNo <> "" Then
Select Case intArgCount
Case 1
Me.lblClient1.Caption = strClientNo
Case 2
Me.lblClient2.Caption = strClientNo
Case 3
Me.lblClient3.Caption = strClientNo
Case 4
Me.lblClient4.Caption = strClientNo
Case 5
Me.lblClient5.Caption = 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(GetSubString(Me.OpenArgs, intArgCount,
;")) ---
Return "472"
If strClientNo <> "" Then
GetArgString = "lblClient" & Trim(Str(intArgCount )) &
".Caption"
Me.Controls(GetArgString) = 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(strName )
Next

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

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).Caption = 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.com" <u21659@uwe> wrote in message
news:5fffc67db8585@uwe...
Thanks. It works. Wonder why it won't work like this....

strCmd = "lblClient" & i
Me(strCmd).Caption = 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
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...
6
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...
8
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
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...
7
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....
14
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...
1
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...
4
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...
3
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
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...

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.