locked
Assign value to a constant RRS feed

  • 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



    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 Function


    Regards, Hans Vogelaar (http://www.eileenslounge.com)

    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

    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 Function


    Regards, Hans Vogelaar (http://www.eileenslounge.com)

    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

    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