Solved

Microsoft Access 2007 - Time Format Help Needed

Posted on 2012-12-20
12
500 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
 
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

708 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now