Results 1 to 6 of 6
  1. #1
    Amyfb is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Mar 2021
    Posts
    64

    Troubleshooting TempVals code snip

    calling all eagle eyes!

    What could be preventing the value of the third variable (EndDate) from being returned when called by this For Each?


    #


    TempVars("gtvUserName").Value = "John Smith"
    TempVars("gtvUserFolder").Value = Environ("HOMEPATH")
    TempVars("gtvEndDate").Value = Format(Now(),"mm/dd/yyyy")
    For Each gtv in TempVars: Debug.Print gtv.Name & ":" & gtv.Value:Next
    gtvUserName:John Smith
    gtvUserFolder:\Users\Amy
    #

    (note: in my code there is no space between : Debug, but I had to add the space here to avoid an emoticon showing up)


    I'm working through some lessons in a book that already has had one typo that I had to correct. Here, I can't fathom what might be going on because I can't see any difference between how all the variables are declared.

    thanks in advance for tips.

    cheerios
    amy

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,906
    Works fine for me?
    However I wrote it as
    Code:
    Sub amy()
    Dim gtv As TempVar
    
    TempVars("gtvUserName").Value = "John Smith"
    TempVars("gtvUserFolder").Value = Environ("HOMEPATH")
    TempVars("gtvEndDate").Value = Format(Now(), "mm/dd/yyyy")
    For Each gtv In TempVars
        Debug.Print gtv.Name & ":" & gtv.Value
    Next
    
    
    End Sub
    and got

    gtvUserName:John Smith
    gtvUserFolder:\Users\Paul
    gtvEndDate:08/24/2021
    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
    Amyfb is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Mar 2021
    Posts
    64
    i was probably editing it

  4. #4
    Amyfb is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Mar 2021
    Posts
    64
    Quote Originally Posted by Welshgasman View Post
    Works fine for me?
    However I wrote it as
    Code:
    Sub amy()
    Dim gtv As TempVar
    
    TempVars("gtvUserName").Value = "John Smith"
    TempVars("gtvUserFolder").Value = Environ("HOMEPATH")
    TempVars("gtvEndDate").Value = Format(Now(), "mm/dd/yyyy")
    For Each gtv In TempVars
        Debug.Print gtv.Name & ":" & gtv.Value
    Next
    
    
    End Sub
    and got

    gtvUserName:John Smith
    gtvUserFolder:\Users\Paul
    gtvEndDate:08/24/2021

    interesting that my book left out the declaration at the beginning. Or maybe I was supposed to have absorbed that lesson and have known to start off with it.

    I added Dim gtv as TempVars to the beginning of the snip and by golly it works perfectly fine!

    thanks eagle!

  5. #5
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,906
    Go into the VBA editor and Tools/Options
    Make sure Require Variable Declaration is ticked

    This will put Option Explicit at the top of new modules.
    Make sure you add it for existing modules.

    Then Access will notify ou when it cannot find a variable, either by you mistyping it, or not even creating it.
    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

  6. #6
    Amyfb is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Mar 2021
    Posts
    64
    Quote Originally Posted by Welshgasman View Post
    Go into the VBA editor and Tools/Options
    Make sure Require Variable Declaration is ticked

    This will put Option Explicit at the top of new modules.
    Make sure you add it for existing modules.

    Then Access will notify ou when it cannot find a variable, either by you mistyping it, or not even creating it.
    That bit of lesson was covered about four pages later ! Thanks again.

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

Similar Threads

  1. Replies: 2
    Last Post: 02-06-2021, 07:54 PM
  2. Need Help Troubleshooting a Database Setup
    By Russellh in forum Access
    Replies: 9
    Last Post: 12-07-2015, 03:59 PM
  3. Troubleshooting unmatched query
    By accessmatt in forum Queries
    Replies: 2
    Last Post: 09-29-2014, 01:52 PM
  4. Need Troubleshooting
    By athyeh in forum Programming
    Replies: 10
    Last Post: 09-26-2013, 12:16 PM
  5. Tab Control Troubleshooting
    By MayaMia in forum Forms
    Replies: 10
    Last Post: 10-09-2012, 12:32 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