Length of String in a Text Box

RascalBird

Registered User.
Local time
Today, 09:34
Joined
Oct 5, 2004
Messages
20
Hi all

I am desperately trying to work out the code I would use if I wanted to determine the length of the string currently in a text box

I need a command button, when it is pressed, to insert some constant text at the current location.

I assumed that this would be done by determining the amount of text currently in the text box and then inserting the text at the current location

Any thoughts on how I could do this or any better ways to perform the same action :confused:

Thanks in advance
 
I don't know what you are referring to when you talk of the Current Location - maybe you are referring to the cursor's position.

You can use the Len() function to determine the length of a string or textbox.
You can use the SelLength property of a textbox to return the length of a selection.
You can use the SelStart property of a textbox determine where the cursor is.
 
String Length

Thanks for the reply

Sorry, I should have explained myself better, I am talking about the current cursor location.

I tried the Len property but didn't really get very far

I tried using

Dim pos as integer

pos = len(textboxname)​

but all i got was compile errors :(
 
Code:
Private Sub cmdMyButton_Click()
    MsgBox "Length: " & Len(Me.MyTextBox)
    MsgBox "Cursor Position: " & Me.MyTextBox.SelStart
End Sub
 
Thanks for that but i'm getting an error of "Method or Data Member Not Found" and access is highlighting the .SelStart portion of text

I'm using Access 2003 any thoughts???
 
Nevermind

Stupid Object Names :eek:

Now lets see how i go with the rest of it
 
Just tell what it is exactly that you want to do and I'll write out the complete code for you rather than me namby-pambying through examples. :)
 
um... OK

At the current cursor location I want the text of "<p></p>" to be inserted and then for the cursor to move to inbetween the two tags

:o
 
There is one problem with that. :(

When you move from the textbox to the command button to click it, then the cursor leaves the textbox and moves to the command button meaning that its current position is lost.
 
mmmmmmmm


What about giving the textbox the focus, determining the number of characters currently in the text box and returning that value?

All I would need to do then would be to add one or two to the current number of characters to make everything easy to read hmmmmmm
 
Thanks for all of your help, just thought I would let you know I worked it out :cool:

Here's the code I used

Code:
Sub paraText_Click()
    Dim pos As Integer
    
  
    
    pos = Len(Me.SectionText)
    SectionText.SetFocus
    
    SectionText.SelStart = pos
    SectionText.SelText = "<p></p>"
    SectionText.SelStart = pos + 3
    
End Sub
 
I didn't realise you were only wanting to add this at the end of a length of text - I had it in my head that you wanted to select somewhere and then click to add the tags in anywhere.

Code:
Private Sub paraText_Click()

    Const ParaTags As String = "<p></p>"

    Me.SectionText = Me.SectionText & ParaTags
    Me.SectionText.SetFocus
    Me.SectionText.SelStart = Instr(1, Me.SectionText, "</p>")

End Sub
 
That would have been the optimum outcome but sometimes something is better than nothing :o

Thanks for that, a slightly neater outcome than the one i found :D
 

Users who are viewing this thread

Back
Top Bottom