Results 1 to 3 of 3
  1. #1
    Tenmakk is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2012
    Posts
    35

    Can I assign a formula to a public variable? Tired of copy+pasting the same equation.

    I have to copy and paste this code into several cells:



    Code:
    dim dtmDate
    dtmDate = Format(Now(), "Short Time")
    I was able to make dtmDate public, but I can't assign it to the formula above. I have to do that in each sub. I also tried a function. Is there another way to do it so I won't have copy and paste it into each sub? This is the function I tried:

    Code:
    Public dtmDate As Date
    
    Public Function CurrTime() As Date
    dtmDate = Format(Now(), "Short Time")
    End Function

    Thank you.

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,521
    A function IS the way...
    just call it from any query,or any sub.
    but functions MUST be assigned at the end to the FCN name, NOT a variable

    Code:
    Public Function CurrTime() As Date
    CurrTime= Format(Now(), "Short Time")
    End Function

  3. #3
    Tenmakk is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2012
    Posts
    35
    Great, works perfectly. Thanks.

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

Similar Threads

  1. Replies: 5
    Last Post: 04-27-2015, 02:40 PM
  2. Pasting a formula into a properties window
    By Lou_Reed in forum Access
    Replies: 8
    Last Post: 04-22-2015, 06:39 AM
  3. Replies: 2
    Last Post: 10-23-2014, 08:19 PM
  4. Replies: 2
    Last Post: 05-28-2013, 12:32 PM
  5. Copy and pasting data in form view help
    By Ash1402 in forum Forms
    Replies: 8
    Last Post: 10-13-2012, 12:36 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