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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Displaying a number as a date in a text box 1

Status
Not open for further replies.

matpj

Technical User
Mar 28, 2001
687
GB
I have an unbound text box that is filled in using an AfterUpdate event in a combo-box on the same form.

The number it is filled in with is of the following format

1010531 - representing 31/05/01

I need to be able to display it as a proper date.
this would involve 'ignoring' the first digit, and then displying the rest of it, in reverse order sections of two digits, seperated with a '/' or '-'

can this be done just by entering a format into the format section of the properties?

thanks for any help
 
Is the number you want to convert a numeric datatype or a string. If it is a string you would have to really convert it somehow to a date that the system is going to understand as a date. If you left it as "010531", after stripping the first digit, the system might think it was 1st May 1931 (or Jan 5th 1931 in the USA), or 2031 depending on your system. So you would really have to convert it first using code.

If it is numeric, then the number 10531 would be converted to some other date by the text box, as dates are stored as numbers by the system, counted in days from 30th Dec 1899.
So, again, you could not rely on the system producing the date you want without some coding. Alex Middleton
 
Hi!

YourText = "1010531"
YourDateFormatText = right(YourText,2) & "/" & _
mid(YourText,4,2) & "/" & _
mid(YourText,2,2)
Aivars


 
Aivars,

thank you both for your responses.

Aivars: is there a way that I could put your formatting into the 'Format' properties for the text box?

The date I am getting, is from Oracle and I think is a sring.
I am not using a query or anything, just getting the data straight from the Orace table, and putting it into a combo box, that then updates the unbound text boxes.

Thankyou for any further help you may be able to offer me

Matthew



 
MyDateStr = Right(Trim(CStr(FunnyDate#)), 2) & "/" & Mid(Trim(CStr(FunnyDate#)), 4, 2) & "/" & Mid(Trim(CStr(FunnyDate#)), 2, 2)

? MyDatesTR

31/05/01


If you have ver 2K, CStr and Trim will avoid the possible confusion between numeric and test/string values being returned


MichaelRed
redmsp@erols.com

There is never time to do it right but there is always time to do it over
 
Again,
how do I apply that to a text field?
I am using no queries for my data - it is simply pasted form an Oracle data, and the only way I can see to format this is by changing the properties of the unbound text-box.

 
MyTextBox = Right(Trim(CStr(FunnyDate#)), 2) & "/" & Mid(Trim(CStr(FunnyDate#)), 4, 2) & "/" & Mid(Trim(CStr(FunnyDate#)), 2, 2)

goes in the Afterupdate event in place of the current assignment of the oracle field to the textbox. You also (obviously?) need to replace "FunnyDate#" with the variable name of the oracle value.


MichaelRed
redmsp@erols.com

There is never time to do it right but there is always time to do it over
 
MyTextBox = Right(Trim(CStr(FunnyDate#)), 2) & "/" & Mid(Trim(CStr(FunnyDate#)), 4, 2) & "/" & Mid(Trim(CStr(FunnyDate#)), 2, 2)

goes in the AfterUpdate event in place of the current assignment of the oracle field to the MyTextBox. You also (obviously?) need to replace MyTextBox with the correct name (of your textbox) and "FunnyDate#" with the variable name of the oracle value.


MichaelRed
redmsp@erols.com

There is never time to do it right but there is always time to do it over
 
=Format(YourDateFormatText,"dd/mm/yy"
Aivars
 
thank you for your replies.



I am filling the text boxes in with an event procedure linked to a combo box.
It has the following code:

Private Sub Description_AfterUpdate()
Text4 = Description.Column(1)
Text6 = Description.Column(2)
Text8 = Description.Column(3)
Text10 = Description.Column(4)
Text12 = Description.Column(5)
End Sub


Can I use your formatting at this stage in the process, so that all of the code is in the same area?

For your info, the combo-box is called 'description' and column 2 - 5 are all the numbers that I need to format in the same way.

any ideas?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top