Solved

Microsoft Access 2007 - Time Format Help Needed

Posted on 2012-12-20
12
535 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
  • 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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
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 49

Accepted Solution

by:
Gustav Brock earned 500 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 49

Expert Comment

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

/gustav
0

Featured Post

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

776 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