Results 1 to 4 of 4
  1. #1
    tuna is offline Novice
    Windows Vista Access 2007
    Join Date
    May 2010
    Posts
    21

    Eval function with variables

    Hi, is it possible to use the eval function with variables e.g. Eval("foo + bar") or Eval("""The value of foo is "" & foo")?



    This is because I have my database settings in a table (one field having the name of the setting and the other containing the value) and I wish to be able to reference variables in the settings value. E.g., for the "MsgOnExit" setting, I would have the string

    "Are you sure you would like to exit " & AppTitle

    Where AppTitle is the name of the database. I would then plan to use Eval at runtime to evaluate the expression to resolve AppTitle to a value. Of course, this may not be the best example as many would argue AppTitle should be a constant, but there are other settings which rely more heavily on variables being able to be resolved at runtime.

    (I'm using a settings table because it allows for a settings GUI and also the ability to variables across sessions.)

    Thanks

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    I don't see that you need the Eval() function at all. Get the value into a variable from the table using your method of choice (DLookup, recordset) then your method works fine:

    MsgBox "Are you sure you would like to exit " & AppTitle
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    tuna is offline Novice
    Windows Vista Access 2007
    Join Date
    May 2010
    Posts
    21
    Thanks. However, I need a way to reference a variable at runtime, not just retrieve it's value at the start since I would need to allow it to change. OK, my previous example probably wasn't very good since AppTitle is supposedly constant throughout each session. I need something like mySetting = foo + bar, where foo and bar are variables that can change during runtime.

    So might you think, why not take into account variable changes by updating the settings table with the changed value? But since my database will be accessed by multiple users I can't write session-specific settings to table (e.g. many "counting" variables) without affecting all users.

    Thanks

    .

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Perhaps I'm not understanding what you're trying to do. If your application is used by multiple users, it should be split. In a split application, each user would have their own copy of the front end, so a table in the front end for users settings/selections would allow users not to conflict with each other.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Shell with Batch Variables
    By robbyaube in forum Programming
    Replies: 2
    Last Post: 12-19-2019, 11:06 AM
  2. Using Public variables between forms/queries/reports
    By dcrake in forum Sample Databases
    Replies: 2
    Last Post: 12-25-2015, 05:44 PM
  3. Want function to get current function name
    By Davis DeBard in forum Programming
    Replies: 2
    Last Post: 08-13-2009, 05:02 AM
  4. replacing dlookup fields with variables
    By msupitar in forum Access
    Replies: 0
    Last Post: 02-18-2009, 12:26 AM
  5. sql in vb variables
    By emilylu3 in forum Programming
    Replies: 3
    Last Post: 03-04-2006, 01:26 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