Full Version: format as date from a listbox
UtterAccess Forums > Microsoft® Access > Access Forms
I have a listbox that when clicked puts the date clicked on in txtPurcDate (unbound)
I use that textbox to supply the date for popup calendar from Allen Browne's site http://allenbrowne.com/ser-51.html by using
Call CalendarFor([txtPurcDate], "")
If I enter the date directly into the textbox the popup works correctly
When I try to use the popup calendar with the date that was put into the textbox from clicking the listbox I get a type mismatch error ( only when I leave the textbox UNbound which I need- if I change it to bound to a date format field it does work), I belive the reason is because its using a string format insted of a date format.
How can I make the date in an unbound textbox a date? I have the properties set to short date format, and I also tried Me.txtPurcDate = Format([lstbxPrevPurcDates], "short date") to try to format the info taken from the listbox neither work.
Have you looked at the CDate() function?
I am confused as to why/how you're using controls to supply a
a value to the calendar control. That particular calendar control is
used to supply values to a textbox.
RuralGuy - I cant seem to make Cdate work either
ce - that calendar control does both, if there is a date in the control to begin with, it opens the calendar to that date then when you choose a new date from the calendar it is returned to that control
So my problem continues..
If I set a breakpoint where I call the calendar and hover over
Call CalendarFor([txtPurcDate], "")
When its working (does NOT have the date in the txtbox from the listbox, but typed in manually) it will show
[txtPurcDate] = 12/12/2007
however when I do the same and the date had been supplied from the listbox I get
[txtPurcDate] = "12/12/2007"
With Quotes, i am assumiing that the problem..
Use CDate() in the code that propagates the value from the ListBox to the TextBox, i.e. before the code you posted.
Thanks Rural Guy and Van, CDate() was the answer after all.
I just needed to use it as Van suggested.
Glad to hear you got it sorted.
You're welcome ... Glad we could help ...
This is a "lo-fi" version of UA. To view the full version with more information, formatting and images, please click here.