Microsoft Access 2007 - Time Format Help Needed

Eileen Murphy
Eileen Murphy used Ask the Experts™
on
I have used this code for years -- had to modify it for 2007+ but it still works great. Allows users to use a simple time picker to populate time fields.

All date fields in question (in the application and form where the code works as well as this one, the form in question) are "Medium Time"

From a main form I have a clock button next to time fields. If they click on it I send the existing time information to the time selection form where the user can change it. Despite the fact that both the table and the forms fields are formatted as "Medium Time" one form only sends the Hour Portion of the time as military time. I have attached screen shots.

CODE:

Private Sub cmdEndTime_Click()

    DoCmd.OpenForm "fClockPopUp", , , , , , "frmSessions - EndTime"
   
    If IsNull(Me.EndTime) = False Then
        Dim strAmorPm As String
        Forms!fClockPopUp!theTime = Me.EndTime
        Forms!fClockPopUp!cboAMPM = UCase(Format(Me.EndTime, "am/pm"))
        Forms!fClockPopUp!txtHour = Format(Me.EndTime, "hh") <<< line in question
        If Minute(Me.EndTime) < 10 Then
            Forms!fClockPopUp!txtMin = "0" & Minute(Me.EndTime)
        Else
            Forms!fClockPopUp!txtMin = Minute(Me.EndTime)
        End If
    End If

End Sub
ScreenShot.doc
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Jeffrey CoachmanMIS Liason
Most Valuable Expert 2012

Commented:
Well the clock shows 7PM, but the "Time Picker" displays 17

In military Time 7PM is 1900 hr, not 1700 (17)
(17/1700, is 5PM)

So it looks like it is doing something with adding a "1" to the 7PM...?
Eileen MurphyIndependent Application Developer

Author

Commented:
You're looking at the End Time - the code is for the Session Begin Time - 5 in military is 17.
Jeffrey CoachmanMIS Liason
Most Valuable Expert 2012

Commented:
oh, ...sorry.

If it were me, I would make a table with the "Time" (as you enter it ex.: 5:30 PM)
and the Hours and minutes broken out.

This way you can type in the time normally, then when you open the "popup", ...you can "Lookup" the corresponding hours and Minutes
This way there is no chance for there being a difference
lookup time
...but I am not sure I know why only *one form* would do this...?

Check the properties of the date fields on that form...
...make sure they are the same as the other forms

As always, lets see if another Expert can see something that I may be missing


JeffCoachman
How to Generate Services Revenue the Easiest Way

This Tuesday! Learn key insights about modern cyber protection services & gain practical strategies to skyrocket business:

- What it takes to build a cloud service portfolio
- How to determine which services will help your unique business grow
- Various use-cases and examples

Jeffrey CoachmanMIS Liason
Most Valuable Expert 2012

Commented:
5:30PM 'Lookup" would be:
5:30 PM
Eileen MurphyIndependent Application Developer

Author

Commented:
I attached screen shot displaying the table and the form field types as well as how the form performed. I don't see how it can work on one form and not the other.

I like the idea of creating a table -- but this has worked for me on a bunch of apps so I'm stumped.
Jeffrey CoachmanMIS Liason
Most Valuable Expert 2012

Commented:
Have you compiled the code?
Have you compacted the db?
A final thing to try would be to create a new form and see if the problem persists
Jeffrey CoachmanMIS Liason
Most Valuable Expert 2012

Commented:
If not then you can post a sample of this database that illustrate this issue

Sample database notes:
1. Back up your database(s).
2. Combine the front and back ends into one database file.
3. Remove any startup options, unless they are relevant to the issue.
4. Remove any records unless they are relevant to the issue.
5. Delete any objects that do not relate directly to the issue.
6. Remove any references to any "linked" files (files outside of the database, Images, OLE Files, ...etc)
7. Remove any references to any third party Active-x Controls (unless they are relevant to the issue)
8. Remove, obfuscate, encrypt, or otherwise disguise, any sensitive data.
9. Unhide any hidden database objects
10. Compile the code. (From the VBA code window, click: Debug-->Compile)
11. Run the compact/Repair utility.
12. Remove any Passwords and/or security.
13. If a form is involved in the issue, set the Modal and Popup properties to: No
    (Again, unless these properties are associated with the issue)
14. Post the explicit steps to replicate the issue.
15. Test the database before posting.

In other words, ...post a database that we can easily open and immediately see and/or troubleshoot the issue.
And if applicable, also include a clear graphical representation of the *Exact* results you are expecting, based on the sample data.
Most Valuable Expert 2015
Distinguished Expert 2018
Commented:
This should work:
  
    If IsNull(Me.EndTime) = False Then
        Forms!fClockPopUp!theTime = Me!EndTime
        Forms!fClockPopUp!cboAMPM = Format(Me!EndTime, "AM/PM")
        Forms!fClockPopUp!txtHour = CStr(Val(Format(Me!EndTime, "h am/pm")))
        Forms!fClockPopUp!txtMin = Format(Me!EndTime, "nn")
    End If

Open in new window

/gustav
Eileen MurphyIndependent Application Developer

Author

Commented:
Will check it out and if it doesn't work will send the db up. Thanks all. Will keep you posted.
Jeffrey CoachmanMIS Liason
Most Valuable Expert 2012

Commented:
Time/Data topics are cactus_data's specialty, so you can continue on with him.

I'll step aside now to avoid confusion.

JeffCoachman
Eileen MurphyIndependent Application Developer

Author

Commented:
That did it. Since this little form has worked so well for me over the years I hated to have to populate a table, etc. Why it worked on one form and not the other within the same app when there didn't appear to be any differences in the form or table field types is a mystery to me.

I thank you for your help and from saving me from the alternative.

Cheers! Happy Holidays!!
Most Valuable Expert 2015
Distinguished Expert 2018

Commented:
Thanks! You are welcome.

/gustav

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial