SelStart scrolls lines out of sight...

R

RzB

I have a text box bound to a memo field. The text box can
contain many (10+) lines. I allow the user to edit the data in
the text box. I'm using txtBox.SelStart = len(memo field) to
position the cursor at the end of the text.

However if there are multiple lines the only one visible is the
line with the cursor on it. All the other lines are scrolled off the
top.

How do I scroll the data in the text box down and still leave my
cursor at the end of the data?

Many thanks,
Roy
 
A

Alex Dybenko

Hi,
well, if you scroll text down and leave cursor at last line - how will user
see where to type?
Perhaps you can make a multiline textbox, so user can see all lines?
 
R

RzB

NB - The text box is large enough to hold 10+ lines. The data in
the memo field is typically 3 or 4 lines long. Easily fits into the text
box. However SelStart = len(memo field ) makes only the last line
visible - right at the top of the text box..The lines above it are not
visible...

The user is confused (only having the last line visible - to him it looks
like he has lost his data) and I need to fix that by getting all the data
in the text box and visible.

I could set SelStart to zero - that would at least put all the data in
the text box. However I would really like to have the three or four
lines all showing and the cursor at the end.... Not possible?

In the longer term perhaps I will do some maths re number of lines
and size of text box etc in case that data is bigger than the text box..
At the moment the size of the text box is much bigger than any of the
data it needs to hold. Will probably always stay that way...

So I'll put off doing the maths for a little while...

But I need to know how to position the data in the text box - I don't
see how to do that...

Many thanks,
Roy
 
D

Dirk Goldgar

RzB said:
I have a text box bound to a memo field. The text box can
contain many (10+) lines. I allow the user to edit the data in
the text box. I'm using txtBox.SelStart = len(memo field) to
position the cursor at the end of the text.

However if there are multiple lines the only one visible is the
line with the cursor on it. All the other lines are scrolled off the
top.

How do I scroll the data in the text box down and still leave my
cursor at the end of the data?

Many thanks,
Roy

I'm not sure I follow you, Roy. In my tests, if the text box is big
enough to display multiple lines, setting SelStart to the end shows the
lines immediately above, too. And, of course, if the text box has its
ScrollBars property set to Vertical, I can use the scroll bar to scroll
the text box.

Can you explain the nature of the problem in more detail? I don't see
it.
 
R

RzB

Dirk,
Many thanks for your help...
Hmm - so it is ok for you... ??
Hmmm have you got embedded LFCRs ?
Perhaps that is affecting it...

I'll do some more digging... and come back in a while..

Thanks,
Roy
 
R

RzB

Dirk,
You can find a picture of the form and the
properties for the txt box here...

http://www.gillandroy.com/mapl

I open the form thus....

DoCmd.OpenForm "frmPrjBldProjectNotes", , , , , acDialog, OpenArgs:=
Str(m_intProjectID)

In the forms Open event is the following code.....Error handling code
removed for clarity...

' ========================================
Private Sub Form_Open(Cancel As Integer)

m_intProjectID = Int(Me.OpenArgs)

Me.RecordSource = "SELECT tblProjects.ID, tblProjects.ProjectName,
tblProjects.ProjectDescription " & _
"FROM tblProjects WHERE (((tblProjects.ID)=" & Str(m_intProjectID) & "));"

If IsNull(Me.txtProjectDescription) Then 'CR# 4513 - Test for null added
Me.txtProjectDescription.SelStart = 0
Else
Me.txtProjectDescription.SelStart = Len(Me.txtProjectDescription)
Me.txtProjectDescription.SetFocus
End If

End Sub
' ========================================

Thanks,
Roy
 
D

Dirk Goldgar

RzB said:
Dirk,
You can find a picture of the form and the
properties for the txt box here...

http://www.gillandroy.com/mapl

I open the form thus....

DoCmd.OpenForm "frmPrjBldProjectNotes", , , , , acDialog, OpenArgs:=
Str(m_intProjectID)

In the forms Open event is the following code.....Error handling code
removed for clarity...

' ========================================
Private Sub Form_Open(Cancel As Integer)

m_intProjectID = Int(Me.OpenArgs)

Me.RecordSource = "SELECT tblProjects.ID, tblProjects.ProjectName,
tblProjects.ProjectDescription " & _
"FROM tblProjects WHERE (((tblProjects.ID)=" & Str(m_intProjectID)
& "));"

If IsNull(Me.txtProjectDescription) Then 'CR# 4513 - Test for null
added Me.txtProjectDescription.SelStart = 0
Else
Me.txtProjectDescription.SelStart = Len(Me.txtProjectDescription)
Me.txtProjectDescription.SetFocus
End If

End Sub
' ========================================

Thanks,
Roy

Care to post a cut-down copy of your database on that website? It
should containing only the elements necessary to demonstrate the
problem, compacted and then zipped to less than 1MB in size (preferably
much smaller), and no sensitive data. I'll have a look at it, time
permitting.

I'm confused by your setting focus to txtProjectDescription *after*
referring to its SelStart property, as I think that property can only be
accessed when the control has the focus. Maybe the control gets the
focus first anyway. But if you post the DB, I can download it and
tinker.
 
R

RzB

Dirk,

I'll see if I can re-create in a "test" db. Cutting down is not an option...

The db is a split db and the front end currently sit around 12MB...

Not a trivial application..

Many thanks for your help...
Roy
 
R

RzB

Dirk,

Ok - there is a simulation of the problem here...

http://pix.gillandroy.com/accessprobs/RzBTestDB.mdb

Start Form1 and click on the Command button - it will open another form and
show the problem straight away.

The table has two records - one with embedded LFCRs and one without...

I have jiggled about with the code but can't see what's wrong.

Interestingly - if you click on the button in the middle ("Go To Project
Details") the text scolls nicely into view... There is NO code behind that
button !!!!!

If you add ........

Me.txtProjectDescription.SetFocus
Me.txtProjectDescription.SelStart = Len(Me.txtProjectDescription)

behind that button - it all works just fine....

Why won't it work from the Open event.... ?

Hmmm...
Many thanks for your help...
Roy.
 
G

Guest

PMFJI,

I downloaded your example mdb, "RzBTestDB.mdb" , and noticed when I tabbed
to a different control, then tabbed back, all of the text was displayed and
the cursor was at the end of the text.

I added a couple of lines at the end of the "Form_Open" code; it seems to
work the way you want it to (without using the timer event code).

The three lines (and comments) are between
the " '------- Added Lines --------- " lines

'=###################################################
' Name : Form_Open
' Copyright 2005 : Roy Brophy - All rights Reserved
' --------------------------------------------------
Private Sub Form_Open(Cancel As Integer)

m_intProjectID = Int(Me.OpenArgs)

Me.RecordSource = "SELECT tblProjects.ID, tblProjects.ProjectName,
tblProjects.ProjectDescription " & _
"FROM tblProjects WHERE (((tblProjects.ID)=" &
Str(m_intProjectID) & "));"

If IsNull(Me.txtProjectDescription) Then 'CR# 4513 - Test for null
added
Me.txtProjectDescription.SelStart = 0
Else
Me.txtProjectDescription.SetFocus
Me.txtProjectDescription.SelStart = Len(Me.txtProjectDescription)

'------- Added Lines ---------
'move to a different control
Me.butCancel.SetFocus
' move back
Me.txtProjectDescription.SetFocus
' now move to the end of the text
Me.txtProjectDescription.SelStart = Len(Me.txtProjectDescription)
'------- Added Lines ---------
End If

End Sub


HTH
 
R

RzB

Steve,

Yes, Yes - well done, that's just right...

Many thanks to you, Alex and Dirk for your help.

Roy
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top