473,406 Members | 2,378 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,406 software developers and data experts.

Curious about odd construction: "#If OutlookEnabled"

prn
254 Expert 100+
I have some inherited code that I don't understand properly. It involves sending email from Access using OLE and Outlook. I've stripped it down to the relevant bits here. Specifically, the construction that (I know that) I don't understand is this:

Expand|Select|Wrap|Line Numbers
  1.     #If OutlookEnabled Then
  2.         Dim olApp As Outlook.Application
  3.         Dim olNewMaiItem As MailItem
  4.         Set olApp = CreateObject("OutLook.Application")
  5.         MsgBox "olApp created - Version = " & olApp.Version
  6.     #Else
  7.         MsgBox "Outlook not enabled"
  8.     #End If
  9.  
(Of course, instead of just displaying the "olApp created" MsgBox, it really does a bunch of other stuff, but I think I mostly understand that part.)

The boolean "OutlookEnabled" is not defined or set anywhere in the module, but it does seem to have a value. At least, if I change its spelling and run the routine, I get the message box saying "Outlook not enabled", so it looks like it somehow gets the value True.

Now, of course, I would expect that OutlookEnabled would really depend on the status outside of Access so I'm not really surprised that it's not set by VBA within Access. The question is where? Pressing F2 gives me the Object Browser, where I can select the Outlook library, for example and browse around for useful objects and properties so that I can refer, e.g. to:

olApp.Version

But OutlookEnabled does not seem to be among the properties (including globals) that I can find there. So where does it come from?

The other obvious quesion I have about the quoted code snippet is: what's up with the "#If" The hash symbol does appear to be meaningful and necessary. But in my admittedly limited library, the "#If" construction is supposed to be stuff that is conditionally compiled, e.g, for debugging, which would lead me to expect that without the #s the whole If-Then-Else-EndIf would be compiled and used all the time. However, if I remove the #s then I get the "Outlook not enabled" message instead of the version message.

In sum, it appears that there is a (system-wide?) variable OutlookEnabled that can only be referred to within a condition using #If.

Why should this be? And what else works like this? Obviously I can simply leave it as it is and use it this way, but somehow, it seems like it might possbly be useful to me in the future if I had some clue about where this came from and what else I might learn from it. :)

Any clues will be gratefully accepted.

Thanks,
Paul
Dec 4 '08 #1
10 2487
FishVal
2,653 Expert 2GB
Hello, prn.

"OutlookEnabled" could be nothing but conditional compiler constant declared with "#Const" conditional compiler directive. Check Access help for this.

Regards,
Fish
Dec 4 '08 #2
prn
254 Expert 100+
Thanks, FishVal. I'm not sure what to make of this, but I appreciate it.

There are at least two tests that I see for the hypothesis that it is a conditional compilation constant.

First, I have searched the entire project. Each and every occurrence of the string "OutlookEnabled" is in the "#If OutlookEnabled" construction, There is not a single instance of "#Const OutlookEnabled" or even of "#Const" anywhere, in that module or any of the others.

Second, if I construct a clear case of a conditional constant:

Expand|Select|Wrap|Line Numbers
  1.     #Const Foo = True
  2.     #If Foo Then
  3.         MsgBox "Foo is conditionally true"
  4.     #Else
  5.         MsgBox "Foo is conditionally false"
  6.     #End If
  7.  
  8.     If Foo Then
  9.         MsgBox "Foo is UNconditionally true"
  10.     Else
  11.         MsgBox "Foo is UNconditionally false"
  12.     End If
  13.  
Running this gives two message boxes (as expected) with the results:
"Foo is conditionally true"
and
"Foo is UNconditionally false"

So the normal If-Then construction (without #) does appear to treat Foo the same way OutlookEnabled appears to work, that is as False.

So I have two tests that seem to give different results. OutlookEnabled does behave the same way as a conditionally defined constant (or variable?), but does not seem to be defined within the vba that Access shows me.

Any ideas?

Thanks,
Paul
Dec 4 '08 #3
FishVal
2,653 Expert 2GB
@prn
:) Seek, seek. It must be.
... Sorry for the old joke.

Second, if I construct a clear case of a conditional constant:

Expand|Select|Wrap|Line Numbers
  1.     #Const Foo = True
  2.     #If Foo Then
  3.         MsgBox "Foo is conditionally true"
  4.     #Else
  5.         MsgBox "Foo is conditionally false"
  6.     #End If
  7.  
  8.     If Foo Then
  9.         MsgBox "Foo is UNconditionally true"
  10.     Else
  11.         MsgBox "Foo is UNconditionally false"
  12.     End If
  13.  
Running this gives two message boxes (as expected) with the results:
"Foo is conditionally true"
and
"Foo is UNconditionally false"

So the normal If-Then construction (without #) does appear to treat Foo the same way OutlookEnabled appears to work, that is as False.

So I have two tests that seem to give different results. OutlookEnabled does behave the same way as a conditionally defined constant (or variable?), but does not seem to be defined within the vba that Access shows me.
The code behaves as expected presuming conditional compilation constans are accessible within conditional compilation statements only (which makes sense because they are used in compilation process only) and variables are allowed to be declared implicitely.

If you want to see the difference you should run it in step-by-step mode.
#If statement unlike If statement is not executed because it is not compiled to executable code.
Dec 4 '08 #4
prn
254 Expert 100+
Thanks again, FishVal!

@FishVal
OK. It is defined. Just not in the (searchable) VBA. :(

In the Visual Basic window, there is a "Project" pane. (View -> Project Explorer) If you right-click on the topmost name in that pane (the name of the overall project) and select "Properties..." you get a dialog box and on the "General" tab of that, there is a textbox called "Conditional Compilation Arguments" and in my case, that textbox contains: "OutlookEnabled = 1". This seems to be equivalent to:
#Const OutlookEnabled = 1
so everything is now clear except for why the original author did it this way. However, I don't expect to ever figure that out considering the overall condition of the code in thsi app. :(

@FishVal
I think I do (now, if not before) understand why conditional compilation (or execution) works as it does, but I admit that I didn't express myself at all well on the subject.

Anyway, thanks, FishVal. You definitely helped my understanding.

Paul
Dec 4 '08 #5
FishVal
2,653 Expert 2GB
@prn
Aha.

Sorry, I didn't realized it from the very beginning since I've never used conditional compiling in VBA (didn't even knew about this option in VBA), but now I see a very good reason.

When the application is being deployed on a machine without Outlook installed, #Outlook is set to false thus excluding from compilation code that uses Outlook object model which otherwise will generate compilation errors.

Nice.
Dec 4 '08 #6
prn
254 Expert 100+
@FishVal
Do you mean that this can be done automatically? I can see how it can be set manually. Do you think it's more convenient to set it here (where the next guy to maintain the app can't find it in a search)?

I'm still somewhat puzzled, but then I tend to prefer text that I can find in a search over somewhat obscure dialogs. That may just be me though.

Thanks again, Fish.

Paul
Dec 4 '08 #7
FishVal
2,653 Expert 2GB
What does mean "automatically"?
Dec 4 '08 #8
prn
254 Expert 100+
@FishVal
"Without human intervention" is what I would mean by it. That is, it would be great if "[w]hen the application is being deployed on a machine without Outlook installed" the process simply detected that Outlook was not available. OTOH, if, as I suspect, Access cannot detect whether Outlook is available without a person changing that value, then my personal bias would be to have the #Const declaration somewhere searchable rather than in what seems to me an obscure dialog. But, that is my own bias and not necessarily shared by anyone else.

Best Regards,
Paul
Dec 5 '08 #9
FishVal
2,653 Expert 2GB
@prn
Access can detect whether Outlook is installed.
  • The easiest way is to detect whether Outllok type library reference is broken. If so code dealing with the library will not work, no matter ehether the reason is library incompatibility or no Outlook installed at all.
  • Installed software could be detected via windows registry.

Once Outlook availability has been determined, VBA could add code line with conditional compiling constant declaration to module via Module class methods.

Regards,
Fish
Dec 5 '08 #10
prn
254 Expert 100+
Interesting ideas. I'll look into them.

Thanks,
Paul
Dec 5 '08 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: LRW | last post by:
I'm not exactly sure how to even ask the question, and I know my terminology is not good as I'm a SQL beginner, but, here goes. I need to find a way to make an if statement within an array...or,...
6
by: Fabrice Régnier | last post by:
Hi ;) Everything is in the title. the prob is "boo" is displayed ! Can you believe it ? Thanx for anyone who can help me. fabrice.
1
by: Mark Richards | last post by:
The solutions for the following problems seems to be simple but I did not found a (convenient) solution: Assume we have a number of elements of the same type under a common parent e.g. <person...
5
by: kmunderwood | last post by:
I am trying to combine "if match=" and "when test" I am a newbie, and have made both work separately, but I can not seem to combine them. This is my xml("index.xml")page(I can not change this,...
145
by: Sidney Cadot | last post by:
Hi all, In a discussion with Tak-Shing Chan the question came up whether the as-if rule can cover I/O functions. Basically, he maintains it can, and I think it doesn't. Consider two...
35
by: David Cleaver | last post by:
Hello all, I was wondering if there were some sort of limitations on the "if" statement? I'm writing a program which needs to check a bunch of conditions all at the same time (basically). And...
2
by: marsarden | last post by:
write code like: int main(void) { int a=10; if(a<20) {} } Compiler ok on dev-cpp . don't we have to add a ";" after if
37
by: jht5945 | last post by:
For example I wrote a function: function Func() { // do something } we can call it like: var obj = new Func(); // call it as a constructor or var result = Func(); // call it as...
0
by: jack | last post by:
IF you want to meet your old school mate's & college mate's of your life there is a chance, just enter school or college details in the below site ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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,...
0
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...

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.