Results 1 to 5 of 5
  1. #1
    Juan4412 is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Dec 2010
    Posts
    209

    Setting Variable In VBA

    I am attempting to use VBA to capture the current time and store it in a variable. I have the syntax below, but I get a Compile Error of Object Required


    Code:
    Dim addedDate As String: Set addedDate = DateValue(CStr(Now()))

  2. #2
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    Remove the Set

  3. #3
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    Try

    Dim addedDate As String: addedDate = DateValue(CStr(Now()))

    though im not a fan of putting them on one line, and I think you've got too many functions in there, I might have:

    Dim addedDate As String
    addedDate = Date()
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  4. #4
    Juan4412 is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Dec 2010
    Posts
    209
    Quote Originally Posted by aytee111 View Post
    Remove the Set
    When do you need to use Set and when do you not?

  5. #5
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    Set is for creating workspaces, not for formulae, equations, etc.

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

Similar Threads

  1. Setting a Report Variable with a string
    By Paul H in forum Programming
    Replies: 2
    Last Post: 07-20-2015, 01:12 PM
  2. Setting Variable Default for Combo Box
    By gazaway in forum Forms
    Replies: 5
    Last Post: 04-08-2013, 10:32 AM
  3. Replies: 2
    Last Post: 08-05-2011, 04:41 PM
  4. Setting Temporary Variable
    By KEVWB in forum Access
    Replies: 1
    Last Post: 02-07-2011, 01:41 PM
  5. Replies: 3
    Last Post: 10-09-2010, 11:53 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