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
> Conditional Compilation - Compiler Directives    
post Jan 12 2004, 09:46 AM

UA Forum + Wiki Administrator
Posts: 14,079
Joined: 26-September 02
From: Sudbury, Ontario, Canada

Occasionally you may want to compile different forms of your code but not have multiple copies of essentially the same database and modules. Compiler directives allow you to determine which code segment should be compiled.

For example, you may be developing code in one version of Access that has certain features that the previous version lacks. In A2002 (XP), the DoCmd.OpenReport method, for instance, has windowmode and openargs arguments. A2000, and most likely all earler versions, do not have these arguments. To make the code compatible with 2000 you have to use a less straightforward approach than is possible in XP. A compiler directive will let you include both versions and select which will be compiled.

First you must declare a compiler constant. You can declare a numeric global compiler constant in your projects properties by typing Version = 1 for example. If you need several compiler constants separate them with a colon (smile.gif.

Altneratively, you can declare local compiler constant strings. In this case the compiler constant is restricted to the module in which it is declared.

#const Version = "A2000"

For any given compiler constant use either the property approach or the module declaration approach. Don't mix them. Note also that the global constant is numeric, the local is string.

Now, to put the constant to work you include the compiler conditional structure wherever you need the code to be version specific:

#if Version = "A2000" Then
'access 2000 code here
' alternative version here
#end if

Depending on the current value of the compiler constant, either the A2000 specific code or the alternaive code will be compiled. If you use the global approach the if statement would refer to the numeric value you specified in the prject properties.

Edited by: argeedblu on 01.12.04.
Go to the top of the page

Custom Search
RSSSearch   Top   Lo-Fi    19th October 2018 - 06:12 AM