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

How to add text in a textbox

Status
Not open for further replies.

Spikemannen

Instructor
Feb 22, 2005
58
SE
I have a form with a textbox that I write comments in.
When I press the button "New Comment" I want todays date to be written in the textbox on the row under the last sentence.

Is that possible? Probably, but how will I do that?
 
On close event of the Form insert this code:

Me!YrTextBox = Me!YrTextbox & vbcrlf & format(date,"DD-MM-YYYY")

Herman

They say that crime doesn't pay... does that mean my job is a crime?
 
Thanks, but how will that affect the click in the button "New Comment"?
 
If you want the date to be inserted as you open the form then do the same on the forms onopen event instead use a docmd.sendkeys "{F2}" to place the user after the date

Herman

They say that crime doesn't pay... does that mean my job is a crime?
 
Superb!!!

One more thing, when I have got the date, how can I get the cursor after the date?
 
Take a look at SelStart and the SelLength properties of the TextBox object.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
I see, have been looking at the SelStart command, but...
I'm not sure how to work with it.

My text box could have several rows with text and I can't tell the selStart exactly where the cursor should be placed.

My code looks like this now, how should it continue?

Private Sub cmdNy_Anteckning_Click()

Me!Anteckningar = Me!Anteckningar & vbCrLf & Format(Date, "YYYY-MM-DD")
Anteckningar.SetFocus
Anteckningar.SelStart

End Sub

Where Anteckningar is my textbox and cmdNy_Anteckning is my button.

Thanks
 
Have you tried this ?
Me!Anteckningar.SelStart = Len(Me!Anteckningar) + 1

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top