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!

display end of text in textbox on lost focus

Status
Not open for further replies.

tractorvix

Technical User
Jun 29, 2004
122
GB
Hi all,

I'm not sure if this is possible, but I've had a user ask if it would be possible to show the end of a textbox field on the lost focus event, rather than it automatically defaulting to the beginning of the text. Is this possible?!

Vix
 
you can change the text align to right on lostfocus, and change it back on the gotfocus...

--------------------
Procrastinate Now!
 
Hi Crowley,

thanks for the response, however this is not exactly what I'm after. Changing the text alignment to right does not show the end of the field.

Basically I have a memo field which often contains lots of information, but the important bit is the contact details which usually appear at the bottom. I want to be able to view the end of the text on the lost focus event.

Vix
 
It is important that the text box and the field should have different names:
Code:
Private Sub Form_Current()
intSuitableLen = 30
If Len(Notes) > intSuitableLen Then
  Me.txtNotes.ControlSource = Chr(61) & Chr(34) & "..." & Mid(Notes, InStr(Len(Notes) - intSuitableLen, Notes, " ")) & Chr(34)
Else
  Me.txtNotes.ControlSource = "Notes"
End If
End Sub

Private Sub txtNotes_GotFocus()
Me.txtNotes.ControlSource = "Notes"
Me.txtNotes.SelStart = Nz(Len(Notes), 0)
End Sub

Private Sub txtNotes_LostFocus()
intSuitableLen = 30
If Len(Notes) > intSuitableLen Then
  Me.txtNotes.ControlSource = Chr(61) & Chr(34) & "..." & Mid(Notes, InStr(Len(Notes) - intSuitableLen, Notes, " ")) & Chr(34)
Else
  Me.txtNotes.ControlSource = "Notes"
End If
End Sub
 
Using Remous code, you may like to try replacing the...

Me.txtNotes.ControlSource = Chr(61) & Chr(34) & "..." & Mid(Notes, InStr(Len(Notes) - intSuitableLen, Notes, " ")) & Chr(34)

with

me.txtNotes.ControlSource = right([fieldname],tbLen)

not for getting to first set the length of the textbox with

tblen = 30 ' the number of characters in view in the textbox

Ian Mayor (UK)
Program Error
Programming is 1% coding, 50% error checking and 49% sweat as your application bombs out in front of the client.
 
I just thought it would be nice to break at a space. :)
 
Also, I think you may find that

me.txtNotes.ControlSource = right([fieldname],tbLen)

Will not work in Access 2000 due to absence of quotes and equals.
 
setting right align does show the end of a bit of text, at least in access 2003...

--------------------
Procrastinate Now!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top