Results 1 to 7 of 7
  1. #1
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    2,097

    Reference the value of a constant

    In the following code,
    Code:
    
    Private Function ShowHELP(ID As Long)
    
    
    helpname = "Help" & ID
    MsgBox Eval(helpname)
    
    
    End Function
    I'm wanting to access the value of a constant. "helpname" is dim'd string and the name of the constant is set in helpname. Using Eval just gives me a runtime error 2482:


    Click image for larger version. 

Name:	2482Error.jpg 
Views:	7 
Size:	19.3 KB 
ID:	52230
    Is it even possible?

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,558
    What is the constant called?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    2,097
    In the current instance, when the error occurs, I'm wanting to Msgbox the string value of the constant HELP6.

  4. #4
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,558
    I do not think you can, as it is two levels removed?

    I have managed this

    Looking at https://learn.microsoft.com/en-us/of...plication.eval
    Attached Thumbnails Attached Thumbnails Greagle.png  
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  5. #5
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    2,097
    I thought that might be the case. I can simply solve the issue by loading the desired strings into an array and use the ID of the desired string to load it from the array.
    Thanks though for your thoughts.
    Bill

  6. #6
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,558
    If you want to find the value of a particular constant, then I think you would need a Select Case statement?
    After all you already know what the value of the constant is, as it cannot be changed.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  7. #7
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,558
    Quote Originally Posted by GraeagleBill View Post
    I thought that might be the case. I can simply solve the issue by loading the desired strings into an array and use the ID of the desired string to load it from the array.
    Thanks though for your thoughts.
    Bill
    That would be a much better way.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Use of Numeric Constant in Query
    By jmichaels in forum Queries
    Replies: 12
    Last Post: 10-24-2020, 02:58 AM
  2. Replies: 15
    Last Post: 11-03-2019, 09:55 AM
  3. Intrinsic Constant Names
    By yeah in forum Programming
    Replies: 14
    Last Post: 05-13-2018, 05:41 AM
  4. a simple getter function for a constant
    By veloopity in forum Programming
    Replies: 10
    Last Post: 10-19-2013, 12:17 PM
  5. Replies: 1
    Last Post: 06-09-2010, 04:19 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums