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.
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
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 Murphy
ASKER
You're looking at the End Time - the code is for the Session Begin Time - 5 in military is 17.
Jeffrey Coachman
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
...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
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
Jeffrey Coachman
5:30PM 'Lookup" would be:
Eileen Murphy
ASKER
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 Coachman
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
Unlimited question asking, solutions, articles and more.
Jeffrey Coachman
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.
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
Will check it out and if it doesn't work will send the db up. Thanks all. Will keep you posted.
Jeffrey Coachman
Time/Data topics are cactus_data's specialty, so you can continue on with him.
I'll step aside now to avoid confusion.
JeffCoachman
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
Eileen Murphy
ASKER
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.
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...?