Full Version: MsgBox tif time is over 00:59
UtterAccess Forums > Microsoft® Access > Access Forms
The users of my database have a tendency to not take any notice of my prompt (label) that explains the time fields is hh:mm. I usually end up with 05:00.
I thought about using a MsgBox (reading up on MsgBox and If Else subs).
Apologies for those sensitive to poor VBA...but I have tried to put soething together and thought I should stop now before I hurt someone.
Private Sub EnquiryTransactionTime_LostFocus()
If (Me.EnquiryTransactionTime > "00:59") Then
MsgBox ("Did this take " & EnquiryTransactionTime & ",vbOKCancel,JustChecking,,)
Here I need to give them options.
OK will move them onto the next field Form!frmEnquiry.EnquiryDetails.SetFocus
Cancel would clear the Me.EnquiryTransactionTime

End If
End Sub
I just wondered if there is a book out there that gives examples of code for 'general' good working practices? I mean a book that just lists examples of code to do this and that - based on real life solutions. Maybe it's to general to make, as no one knows how long a piece of string is, but I'm sure people have modules set up that they continually use/alter for most applications they make - i.e. buttons that always requery database, msgboxs for validating, etc, etc. So maybe a book could be produced based on people's modules - and descriptions of what they do...I'll go now as I'm waffling....
Thanks for any clarity you can give me on my msgbox validating question.
Give them 2 unbound controls labeled hours and minutes. Then use the TimeSerial function to set a bound control to the Time value.
Hi Scott
think you have mentioned this before. I tried it out - giving them 2 seperate boxes/controls an Hours and Minutes.
Othen created a non visible control bound to the Time field in the table that was the result of these controls
I couldn't get it to work, but I don't remember using the timeserial function.
I'll have another go...
In the After Update of txtHours put:
If IsNull(Me.txtMinutes) Then
If MsgBox("No Minutes entered",vbOKCancel)=vbOK Then
Me.txtTime = TimeSerial(Nz(Me.txtHours),0,Nz(me.txtMinutes,0),0)
End If
End IF
For txtMinutes use:
If IsNull(Me.txtHours) Then
If MsgBox("No Hours entered",vbOKCancel)=vbOK Then
Me.txtTime = TimeSerial(Nz(Me.txtHours),0,Nz(me.txtMinutes,0),0)
End If
End IF
From reading the TimeSerial help file I am under the impression that it will change an entry of Hours (00) Minutes (15) into 00:15:00 AM - an actual time on a clock, not an amount of time - 15 minutes.
nbound field -UHours
unbound field -UMinutes
Bound field -EnquiryTime (formatted Short Time)
Dim EnquiryTime
EnquiryTime = TimeSerial (UHours,UMinutes)
Does that make sense?
You need to understand how time is stored in access. A Date/Time datatype is a Double precision number where the Integer portion represents the number of days since 12/30/1899. The decimal portion represents a fraction of a day. So that 6AM or 6 hours = .25. If you want a time value so that you can do time arithmetic, then you need to store it that way. But understand that a time formatted display will ignore the Integer portion and only display the fraction.
In that case, I should probably use it then, but I'm not clear on how I can get the underlying jnxtbl to store the combined entries of my 2 boxes.
Is it something like I mentioned below? With the code placed in which box/event?
EnquiryTime = TimeSerial (UHours,UMinutes,)
I gave you the code.
e.txttime is the control bound to the field.
So you did. Sorry I missed that posting.
Hi Scott

Just put your code in where you mentioned, adn I get a compile error message: Wrong number of arguments or invalid property assignemnt.

I have checked it and I have entered it as you said. I have changed your names for the txthours to my unbound control names, and I have changed your name for the bound control to mine.

It seems to highlight (blue) the TimeSerial name in the code.

Any ideas. I understand the principle of the code, but I'm not sure why it sees the TimeSerial part as the place where it goes wrong - if that's what the highlight means.

I am looking at it ,but I imagine you will understand long before I do...

Just wondered if it has any effect that the hours/minutes are ina subfrom on the main form? The code is in the subform, but I expect it doesn't matter.
Edited by: Mike11 on Fri Jun 16 5:38:33 EDT 2006.
Because there was a misplaced parentheses. Should have been:
e.txtTime = TimeSerial(Nz(Me.txtHours,0),Nz(me.txtMinutes,0),0)
A couple of points to add here. Most of the time when we give you code snippets, the code is off the top of our heads and untested. There may be syntax errors or typos. One of the most important skills in writing code is the ability to debug. The error message told you the problem. The TimeSerial function takes 3 arguments; Hours, Minutes and Seconds. So somehow the number of arguments wasn't correct. Also the Nz function takes 2 arguments; the value to test and the replacement value. A quick look at the code showed the first Nz, didn't have a replacement value which lead to the problem.
Couldn't agree more.
This is a "lo-fi" version of UA. To view the full version with more information, formatting and images, please click here.