473,781 Members | 2,702 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Curious about odd construction: "#If OutlookEnabled"

prn
254 Recognized Expert Contributor
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 2530
FishVal
2,653 Recognized Expert Specialist
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 Recognized Expert Contributor
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 Recognized Expert Specialist
@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 Recognized Expert Contributor
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 "Conditiona l Compilation Arguments" and in my case, that textbox contains: "OutlookEna bled = 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 Recognized Expert Specialist
@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 Recognized Expert Contributor
@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 Recognized Expert Specialist
What does mean "automatically" ?
Dec 4 '08 #8
prn
254 Recognized Expert Contributor
@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 Recognized Expert Specialist
@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

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

Similar topics

9
4401
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, the "while" portion of a recordset. The best way I can ask is show what I mean. http://oscarguy.mechphisto.net/awardbrowse.php If you go there and select an award (like Best Picture), leave the year field alone, and select YES and submit,...
6
2463
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
18909
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 ... myattr="aaa">Paul</person> <person ... myattr="bbb">Peter</person> <person ... myattr="ccc">Karl</person> ..... <person ... myattr="ddd">Stan</person>
5
2080
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, it comes to me this way. <?xml version="1.0" encoding="iso-8859-1" ?>
145
6349
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 programs: /*** a.c ***/
35
2741
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 I'm pretty sure the rest of the program is working just fine. The only thing I could think might be wrong is that the if statement can only hold so many values in itself? Let me show what I'm doing: if (table001]>>5]&b&0x1f] != 0 &&
2
2073
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
3987
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 a function
0
881
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 http://www.batchmates.com/institution/regform.asp?refid=1529710&reflink=31481 please forward to ur friend's tell to them forward this message to there friend's
0
9639
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
9474
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10143
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...
1
10076
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8964
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
7486
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
6729
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
5375
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
5507
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.