Trying to insert a date within a string in a textbox
I am trying to insert a date within a string in a textbox, such as:
“Mary had a little 23-Jul-06 lamb, its fleece was white as snow. 23-Aug-06”.
Every time I try to insert the date it clears the text from the textbox. I’ve tried everything I can think of, but I’m unable to insert it without clearing the text. The DATE function seems to have a built in ‘clear’ function so each time its called it clears the textbox. Is there a way of disabling this phantom ‘clear’ function? See my coding attempts below:
Private Sub cmdDate_Click()
I've tried the following:
1. Text1.Text = Date
2. dim date as string
text1.text = date
3. text1.text = str(date)
4. text1.text = Format(Now, "dd mmmm yyyy")
End Sub
None of them do what I want. It seems to me that using the STR() function should convert the numeric date to a string that could then be inserted. I don’t know whether there is a textbox property I should be setting at design time that would eliminate the “clearing” effect of the Date function. Can anyone help me? I thank any of you in advance for helping me.
Urbaud
Insert the date several times in a textbox
Hi Phil,
Thank you for replying to my post. I tried your suggested code and it works. However, I realize that I didn’t make myself clear in the post. I’m talking about large bocks of text, not a single line of text. I have a program and the textbox in it is set to multiline. When I see a block of text that I want to keep, I just paste it into the text box.
In the past I have had to type the date but that gets tiresome, so I thought I’d create a DATE command button which would allow me to place the cursor anywhere in the text, then click the Date button and presto, the date is inserted. Each time I try new code (as cited above), none of it works and when the date is inserted it clears all of the text. With your code, you were able to choose initially (at design time) where to place the date, the 18th character position. I don’t know at design time where I will be placing the date or dates, so that’s why I need to be able to just place the cursor any place and click the DATE button. If I have a large body of text I may want to insert the date at several places throughout the text.
Is there a way of turning the date into a string that will fit into the text without clearing it? I thought the STR() function would do it, but obviously not. I sure hope this reply is clearer in terms of what I want to do. Any suggestions would be most appreciated. Thanks again for replying.
Dan (urbaud)