Results 1 to 7 of 7
  1. #1
    dcdimon's Avatar
    dcdimon is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2013
    Location
    Bradenton, FL
    Posts
    71

    Hour() Function acting strangely - or not at all [datepart("h") vs hour()]

    Okay, I've got some weirdness going on in my vba script and I'm not sure why. I have a script that is comparing the hour that is hardcoded to a form against the hour of the current time.


    Code:
    me.FormHrtxt = Hour(now())
    If it is equal then other script runs, if not then nothing happens and the page is locked. It works fine in my development version of the database. However, when I import the script into the user version of the database, which is essentially the file I made the development copy from, it no longer functions as expected.

    In normal scripting the Hour function shows as what I just typed - the word hour with a capital H. In the user database the hour function has changed to the word hour with a capital H and O - it now looks like this in the script HOur(Now()). I'm getting alternating error messages when the page loads/script runs. Either 'datatype mismatch' or 'can't find field HOur in expression'. I have no idea why this is happening. Older script that has the Hour() function in it now shows HOur() as well - but those seem to be working alright.

    I've modified the newer script I brought over to use the Datepart() function:
    Code:
    Datepart("h",(Now())
    So it's working as intended, but I am at a loss as to why the Hour() function is no longer running as expected. My initial assumption is that the dbs is corrupted somehow. I did try opening a blank dbs and importing over the components of the original and I found the same issue. However a new database without the import sees the Hour() function correctly.

    It's all a bit maddening - and caused me quite a bit of cursing until I changed over to the Datepart() function. Has anyone ever experienced this problem? Any ideas? Or should I just chalk it up to the Access gremlins?

    Thanks,
    DD

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    It is acting like you have your own HOur() function defined somewhere.

  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,521
    My first thought is that there may be a field/control/user function with that name, and Access is confused about which you're referring to. I'd hunt for that.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  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
    Oops, sorry Allan, slow typing on an iPad.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    Hi -

    A couple of things to look for:

    There is a form with a control named "HOur" on it, and Access is confused as to ehat is being referred to or
    There is a function or sub called "HOur" in a code module, and if it is in a form module, you won't always get the error.

    You could check the second one by doing a whole-project search for "Sub HOur" or "Function HOur" with the Match Case option on. Even a search for just "HOur" might work if you use match case.

    HTH

    John

    PS Sorry guys - your posts wern't there when I strted the reply! At least we're all on the same page!
    Last edited by John_G; 07-25-2014 at 08:05 AM. Reason: Add a line!

  6. #6
    dcdimon's Avatar
    dcdimon is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2013
    Location
    Bradenton, FL
    Posts
    71
    Hi All,

    I thought of that when I saw that it was changing the Hour to HOur. I did a whole project search for "HOur" by case and "Function HO" and found nothing.

    I didn't think about looking for a control with the HOur name though.

    There are several people working on this database - design phase - so occasionally we get some weirdness because of that. However, these forms were designed by someone that knows not to use Date, Time, Hour..etc as the name of anything because they're reserved for Access.

    I'll try searching again and look at the controls. Because the syntax is changing, I really think it's a function issue, I just don't know where it is.

    Thanks for the help,

    DD

  7. #7
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    You could also try *importing* the stubborn DB into a fresh new db and see if the problem follows. It might just be some corruption.
    http://www.btabdevelopment.com/ts/impnew

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

Similar Threads

  1. Replies: 1
    Last Post: 10-20-2013, 10:04 AM
  2. Trying to find hour that has most attempts
    By pdpeterson87 in forum Queries
    Replies: 5
    Last Post: 10-08-2013, 03:52 PM
  3. Replies: 2
    Last Post: 11-04-2011, 02:45 AM
  4. Time minus one for hour.
    By brianb in forum Queries
    Replies: 2
    Last Post: 03-09-2011, 11:02 AM
  5. Replies: 3
    Last Post: 04-10-2010, 10:22 AM

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