Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Textbox time formatting without seconds 3

Status
Not open for further replies.

BrianLe

Programmer
Feb 19, 2002
229
US
In AC97, how do you format a textbox to show date and time, but without the seconds. I have tbxStartUnload that is created with the following code.

Code:
Private Sub lbxStartHour_Click()

Me!tbxStartUnload = CVDate(Me!ActiveXCtl93 & " " & Me!lbxStartHour)
End Sub

A typical result is 10/28/07 8:30:00 AM.

How do I get it to show only 10/28/07 8:30 AM, so the Date formatted field in the table will also be 10/28/07 8:30 AM?

Thanks,

Brian

 
You may use the Format function to get a formatted string.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks PH. I created a custom format in the Format property of the textbox. I set it to mm/dd/yyyy hh:mm AM/PM. Is that the best approach?

Thanks,

Brian

 
Yes, that will work.

It is better to use nn (rather than mm) for minutes though, otherwise it may be confused with the month digits in some formats:

mm/dd/yyyy hh:nn AM/PM

Ed Metcalfe

Please do not feed the trolls.....
 
How are ya BrianLe . . .

. . . and this:
Code:
[blue]Me!tbxStartUnload = Format(Me!ActiveXCtl93, "mmm dd,yyyy") & " " & _
                    Format(Me!lbxStartHour, "hh:nn am/pm")[/blue]

Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997
 
Thanks Ed and PH. However, I can't get the code method to work. It still shows the time with the seconds (12:30:00 AM). I've tried shortening the code to just format the time part. Any ideas?

Code:
 Me!tbxStartUnload = Format(Me!lbxStartHour, "hh:nn am/pm")

Thanks,

Brian
 
Any chance there are format properties set on the text box and or the underlying table field? I would think your code would override those settings, but that may not be the case.
 
I got the code to work with this.

Code:
Private Sub lbxStartHour_Click()

Me!tbxStartUnload.Format = "mm/dd/yyyy hh.nn AM/PM"
Me!tbxStartUnload = CVDate(Me!ActiveXCtl93 & " " & Me!lbxStartHour)

Thanks,

Brian
 
Brian,

You may want to use CDate() rather than CVDate(). It appears CVDate() is there for legacy compatibility.

VBA Help said:
CDate recognizes date formats according to the locale setting of your system. The correct order of day, month, and year may not be determined if it is provided in a format other than one of the recognized date settings. In addition, a long date format is not recognized if it also contains the day-of-the-week string.

A CVDate function is also provided for compatibility with previous versions of Visual Basic. The syntax of the CVDate function is identical to the CDate function, however, CVDate returns a Variant whose subtype is Date instead of an actual Date type. Since there is now an intrinsic Date type, there is no further need for CVDate. The same effect can be achieved by converting an expression to a Date, and then assigning it to a Variant. This technique is consistent with the conversion of all other intrinsic types to their equivalent Variant subtypes.

Ed Metcalfe.

Please do not feed the trolls.....
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top