UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> Randomize Time In Vba, Access 2016    
 
   
waltb1937
post Aug 22 2019, 01:40 PM
Post#1



Posts: 5
Joined: 5-February 17



Have been trying to randomize time, can randomize regular number but no luck with time.
Tried to randomize time between 8:30 AM and 11:30 AM and end-up with zero this is the last thing i tried ... TOD![Time] = Int((1100 - 8.5 + 1) * Rnd + 8.5)
Appreciate any help
Thanks
Walt B
Go to the top of the page
 
theDBguy
post Aug 22 2019, 01:53 PM
Post#2


Access Wiki and Forums Moderator
Posts: 76,375
Joined: 19-June 07
From: SunnySandyEggo


Hi Walt. Welcome to UA! welcome2UA.gif

Give this a few tries in the Immediate Window:

CODE
?dateadd("n",int(690-510-1)*rnd+510,#00:00#)

--------------------
Just my 2 cents... "And if I claim to be a wise man, it surely means that I don't know" - Kansas
Access Website | Access Blog | Email
Go to the top of the page
 
ADezii
post Aug 22 2019, 03:27 PM
Post#3



Posts: 2,674
Joined: 4-February 07
From: USA, Florida, Delray Beach


  1. I created a small Demo for you you that will generate X number (25 in this Demo) of Time Values between the Range of 8:30 A.M. and 11:30 A.M. Just change the Value of the Constant conLOOPS to increase/decrease the number of Random Times generated within the Range.
  2. Code Definition:
    CODE
    Dim intLow As Double
    Dim intHigh As Double
    Dim intCtr As Integer
    Const conLOOPS = 25        'Number of Random Values

    intLow = 0
    intHigh = 180

    Randomize

    For intCtr = 1 To conLOOPS
      Debug.Print Format$(intCtr, "00"), _
                  Format$(DateAdd("n", (intHigh - intLow + 1) * Rnd + intLow, # _
                  8:30:00 AM#), "hh:nn AM/PM")
    Next
  3. OUTPUT:
    CODE
    01            10:48 AM
    02            09:56 AM
    03            10:01 AM
    04            11:00 AM
    05            11:00 AM
    06            09:33 AM
    07            11:18 AM
    08            10:38 AM
    09            08:33 AM
    10            10:13 AM
    11            08:53 AM
    12            10:45 AM
    13            09:06 AM
    14            09:34 AM
    15            08:38 AM
    16            09:52 AM
    17            11:19 AM
    18            11:01 AM
    19            10:57 AM
    20            10:45 AM
    21            10:07 AM
    22            11:06 AM
    23            09:54 AM
    24            11:00 AM
    25            09:47 AM
  4. Hope this helps.
Go to the top of the page
 


Custom Search


RSSSearch   Top   Lo-Fi    14th October 2019 - 04:00 AM