If Then Const

S

Scafidel

I have an Access Form that uses the following code to open a Word document
which works fine:
Const conTEMPLATE_NAME = "C:\FORMS\Form_A.dotm"

Now, I would like a choice of two documents, so I've added a check box (EXB)
to the form and tried the following code, but get the error, (Else Without
If):

If (Forms!DocMaker!EXB) = True Then Const conTEMPLATE_NAME =
"C:\FORMS\Form_B.dotm"
Else
Const conTEMPLATE_NAME = "C:\FORMS\Form_A.dotm"
End If
End Sub

I've tried putting this in brackets and that in parenthesis, but without
luck. Any suggestions?
Thanks.
 
A

Allen Browne

Use a variable instead of a constant.

Replace:
Const conTEMPLATE_NAME = "C:\FORMS\Form_A.dotm"
with:
Dim strTEMPLATE_NAME As String
You can then assign a value to the string.

That's the difference between a variable (something that can vary as you
assign values to it), and a constant (something that cannot vary.)
 
G

George Nicholson

Make sure you are using the correct If..Then..Else structure;

If SomeCondition Then
Do This
Else
Do This
End If

There is also a one-line version of If..Then:
If SomeCondition Then DoThis

You can not use the 2 structures together, which it seems is what you are
doing. That is causing the "Else Without If" error: You have already fed it
a complete single-line If..Then, so it isn't expecting an Else and can't
associate it with anything.
 
S

Scafidel

Thanks! I needed both responses!
--
Scafidel
Lafayette, Louisiana


George Nicholson said:
Make sure you are using the correct If..Then..Else structure;

If SomeCondition Then
Do This
Else
Do This
End If

There is also a one-line version of If..Then:
If SomeCondition Then DoThis

You can not use the 2 structures together, which it seems is what you are
doing. That is causing the "Else Without If" error: You have already fed it
a complete single-line If..Then, so it isn't expecting an Else and can't
associate it with anything.
 
Top