Answered by:
Assign value to a constant

Question
-
Hi
This works:
Const StrPath = "C:\files\"
But this doesnt:
Const StrPath = Forms![All].[txt_string]
Is there a way?
Cheers // Peter Forss Stockholm
- Edited by ForssPeterNova Tuesday, October 29, 2019 5:06 AM
Monday, October 28, 2019 2:27 PM
Answers
-
You cannot assign an expression that has to be evaluated to a constant. So declare StrPath as a variable instead and assign the value when you need it. Or define StrPath as a function:
Function StrPath() As String
StrPath = Forms![All].[txt_string]
End FunctionRegards, Hans Vogelaar (http://www.eileenslounge.com)
- Marked as answer by ForssPeterNova Monday, October 28, 2019 3:33 PM
Monday, October 28, 2019 2:40 PM -
Constants are constant and can not dynamically be populated, as you are trying to do at runtime. So instead, you need to use a standard variable (string in this case)
Dim StrPath As String StrPath = Forms![All].[txt_string]
Daniel Pineault, 2010-2019 Microsoft MVP
Professional Support: http://www.cardaconsultants.com
MS Access Tips and Code Samples: http://www.devhut.net- Marked as answer by ForssPeterNova Monday, October 28, 2019 3:33 PM
Monday, October 28, 2019 2:48 PM
All replies
-
You cannot assign an expression that has to be evaluated to a constant. So declare StrPath as a variable instead and assign the value when you need it. Or define StrPath as a function:
Function StrPath() As String
StrPath = Forms![All].[txt_string]
End FunctionRegards, Hans Vogelaar (http://www.eileenslounge.com)
- Marked as answer by ForssPeterNova Monday, October 28, 2019 3:33 PM
Monday, October 28, 2019 2:40 PM -
Constants are constant and can not dynamically be populated, as you are trying to do at runtime. So instead, you need to use a standard variable (string in this case)
Dim StrPath As String StrPath = Forms![All].[txt_string]
Daniel Pineault, 2010-2019 Microsoft MVP
Professional Support: http://www.cardaconsultants.com
MS Access Tips and Code Samples: http://www.devhut.net- Marked as answer by ForssPeterNova Monday, October 28, 2019 3:33 PM
Monday, October 28, 2019 2:48 PM -
Thanks Hans
Cheers // Peter Forss Stockholm
Monday, October 28, 2019 3:33 PM -
Thanks Daniel
I will use it in the beautiful CDO mail code you recently posted.
Cheers // Peter Forss Stockholm
Monday, October 28, 2019 3:38 PM