If Then Const

  • Thread starter Thread starter Scafidel
  • Start date Start date
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.
 
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.)
 
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.
 
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top