Microsoft Access conditional compilation

I am experimenting with conditional compilation for my project.  I am testing the code below but it does not work for me.
The code is in a Microsoft access form.    Can this be made to work?
I would appreciate any help.

Option Compare Database
Option Explicit
Const Const_var  As String = "Three"

Open in new window



#If Const_var = "one" Then
    MsgBox ("One")
#End If

#If Const_var = "Two" Then
    MsgBox ("Two")
#End If


#If Const_var = "Three" Then
    MsgBox ("Three")
#End If

Open in new window

peispudAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Nick67Commented:
Your declaration is wrong.
Like this.

Option Compare Database
Option Explicit
'Const Const_Var  As String = "Three"
'nope, not happening
#Const Const_Var1 = "Three"
'In the VBA project Properties you can define your own, but a string ain't happening there, only integer
'This one will be module specific
Those defined in the project are global


Private Sub Form_Open(Cancel As Integer)
#If Const_Var = 1 Then
    MsgBox ("One")
#End If

#If Const_Var = 2 Then
    MsgBox ("Two")
#End If

#If Const_Var = 3 Then
    MsgBox ("Three")
#End If

#If Nick67 = 4 Then
    Dim TheMsg As String
    TheMsg = "Nicky's here"
    MsgBox (TheMsg)
#End If

#If Const_Var1 = "Three" Then
    MsgBox ("3")
#End If

End Sub

Open in new window

Sample attached
https://usefulgyaan.wordpress.com/2013/06/26/vba-trick-of-the-week-conditional-compiling/
http://www.utteraccess.com/wiki/index.php/Conditional_Compilation#User_Defined_Compiler_Constants
https://msdn.microsoft.com/en-us/library/aa240847(v=vs.60).aspx

What are you hoping to use it for?
I tried using it for making a cross-versions file that would gracefully degrade the References in the project.
You can detect a busted reference.
You can't fix one though -- which makes detecting them pointless.
Conditional-compilation.mdb
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
peispudAuthor Commented:
You asked ...  What are you hoping to use it for?
Answer  :   I have three forms that are exactly the same except for one field.  I was hoping to work on one form and copy/paste to  form 2 and 3.  The conditional compilation would look at the constant  and compile accordingly.

I wanted to explore that idea.   I now understand  the information.
I will use conditional compilation again, but not in my current project.

Thank you for your time.
0
Nick67Commented:
I have three forms that are exactly the same except for one field.
You can pass in OpenArgs when a form opens.
You can set the RecordSource at that time
You can set the ControlSource of any control at any time.
You can set the Caption at Open() time, so it looks like 3 different forms are in play with only one object
There's lots of ways to skin that cat.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.