?
Solved

Microsoft Access 2007 - Time Format Help Needed

Posted on 2012-12-20
12
Medium Priority
?
574 Views
Last Modified: 2012-12-21
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
0
Comment
Question by:Ei0914
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
  • 2
12 Comments
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 38711012
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...?
0
 

Author Comment

by:Ei0914
ID: 38711036
You're looking at the End Time - the code is for the Session Begin Time - 5 in military is 17.
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 38711335
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
0
Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 38711339
5:30PM 'Lookup" would be:
5:30 PM
0
 

Author Comment

by:Ei0914
ID: 38711365
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.
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 38711808
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
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 38711811
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.
0
 
LVL 51

Accepted Solution

by:
Gustav Brock earned 2000 total points
ID: 38712325
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
0
 

Author Comment

by:Ei0914
ID: 38713276
Will check it out and if it doesn't work will send the db up. Thanks all. Will keep you posted.
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 38713665
Time/Data topics are cactus_data's specialty, so you can continue on with him.

I'll step aside now to avoid confusion.

JeffCoachman
0
 

Author Closing Comment

by:Ei0914
ID: 38713978
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!!
0
 
LVL 51

Expert Comment

by:Gustav Brock
ID: 38714516
Thanks! You are welcome.

/gustav
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question