By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,392 Members | 1,561 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,392 IT Pros & Developers. It's quick & easy.

How to have cursor focussed on center part of contents

P: n/a
I have a Notes block and have to buttons to have the cusror moved to
the top as well as the bottom of the contents.

Here is the VB of the buttons:

To top:
Notes.SelStart=0

To bottom:
Notes.SetFocus
Notes.SelStart=Len(Notes.Value)

? How to have the cursor moved to the center part. If the contents
consists of 30 lines, it should move to line 15. For 40 lines, to line
20 etc.

Bart
Acc 2003

Oct 7 '06 #1
Share this Question
Share on Google+
8 Replies


P: n/a
AA Arens wrote:
I have a Notes block and have to buttons to have the cusror moved to
the top as well as the bottom of the contents.

Here is the VB of the buttons:

To top:
Notes.SelStart=0

To bottom:
Notes.SetFocus
Notes.SelStart=Len(Notes.Value)

? How to have the cursor moved to the center part. If the contents
consists of 30 lines, it should move to line 15. For 40 lines, to line
20 etc.

Bart
Acc 2003
'something like this may get you close
Private Sub Comments_GotFocus()
Dim colList As New Collection
Dim strVal As Variant
Dim lngPos As Long
Dim lngStart As Long
Dim lngLines As Integer

strVal = Me.Comments

If Not IsNull(strVal) Then
Do While True
lngLines = lngLines + 1
lngPos = InStr(strVal, Chr(13) & Chr(10))
colList.Add lngStart
If lngPos 0 Then
lngStart = lngStart + lngPos + 1
strVal = Mid(strVal, lngPos + 2)
Else
Exit Do
End If
Loop
End If

lngStart = colList(Int(lngLines / 2) + IIf(lngLines Mod 2 = 1, 1, 0))
Me.Comments.SelStart = lngStart

End Sub
Oct 7 '06 #2

P: n/a
Hi Salad, thaks for the input.

It is indeed in the right direction, though I get the message:

Run-Time error 2185
Cannot reference a property or method for a control unless control has
focus.

I get the error both when I put your script under GetFocus as Click
procedures.
at
Me.Notes.SelStart = lngStart

Bart
salad wrote:
AA Arens wrote:
I have a Notes block and have to buttons to have the cusror moved to
the top as well as the bottom of the contents.

Here is the VB of the buttons:

To top:
Notes.SelStart=0

To bottom:
Notes.SetFocus
Notes.SelStart=Len(Notes.Value)

? How to have the cursor moved to the center part. If the contents
consists of 30 lines, it should move to line 15. For 40 lines, to line
20 etc.

Bart
Acc 2003

'something like this may get you close
Private Sub Comments_GotFocus()
Dim colList As New Collection
Dim strVal As Variant
Dim lngPos As Long
Dim lngStart As Long
Dim lngLines As Integer

strVal = Me.Comments

If Not IsNull(strVal) Then
Do While True
lngLines = lngLines + 1
lngPos = InStr(strVal, Chr(13) & Chr(10))
colList.Add lngStart
If lngPos 0 Then
lngStart = lngStart + lngPos + 1
strVal = Mid(strVal, lngPos + 2)
Else
Exit Do
End If
Loop
End If

lngStart = colList(Int(lngLines / 2) + IIf(lngLines Mod 2 = 1, 1, 0))
Me.Comments.SelStart = lngStart

End Sub
Oct 7 '06 #3

P: n/a
AA Arens wrote:
Hi Salad, thaks for the input.

It is indeed in the right direction, though I get the message:

Run-Time error 2185
Cannot reference a property or method for a control unless control has
focus.

I get the error both when I put your script under GetFocus as Click
procedures.
at
Me.Notes.SelStart = lngStart

Bart
First, I would put the two lines below the Endif inside the Endif. Is
it possible the Notes field is Null?

I have no idea what the value of lngStart is.

Do all references to Comments now refer to Notes?

I'd step through the code.
>
salad wrote:
>>AA Arens wrote:
>>>I have a Notes block and have to buttons to have the cusror moved to
the top as well as the bottom of the contents.

Here is the VB of the buttons:

To top:
Notes.SelStart=0

To bottom:
Notes.SetFocus
Notes.SelStart=Len(Notes.Value)

? How to have the cursor moved to the center part. If the contents
consists of 30 lines, it should move to line 15. For 40 lines, to line
20 etc.

Bart
Acc 2003

'something like this may get you close
Private Sub Comments_GotFocus()
Dim colList As New Collection
Dim strVal As Variant
Dim lngPos As Long
Dim lngStart As Long
Dim lngLines As Integer

strVal = Me.Comments

If Not IsNull(strVal) Then
Do While True
lngLines = lngLines + 1
lngPos = InStr(strVal, Chr(13) & Chr(10))
colList.Add lngStart
If lngPos 0 Then
lngStart = lngStart + lngPos + 1
strVal = Mid(strVal, lngPos + 2)
Else
Exit Do
End If
Loop
End If

lngStart = colList(Int(lngLines / 2) + IIf(lngLines Mod 2 = 1, 1, 0))
Me.Comments.SelStart = lngStart

End Sub

Oct 8 '06 #4

P: n/a
AA Arens wrote:
Hi Salad, thaks for the input.

It is indeed in the right direction, though I get the message:

Run-Time error 2185
Cannot reference a property or method for a control unless control has
focus.

I get the error both when I put your script under GetFocus as Click
procedures.
at
Me.Notes.SelStart = lngStart
Yes, you need to put the last 2 lines
lngStart = colList(Int(lngLines / 2) + IIf(lngLines Mod 2 = 1, 1, 0))
Me.Comments.SelStart = lngStart
just above the Endif

I put the code in the GotFocus for the memo field. Not sure what you
mean by Click procedures.

Ensure all refs to Comments now reflects Notes since that's the name of
your memo field.

Bart
salad wrote:
>>AA Arens wrote:
>>>I have a Notes block and have to buttons to have the cusror moved to
the top as well as the bottom of the contents.

Here is the VB of the buttons:

To top:
Notes.SelStart=0

To bottom:
Notes.SetFocus
Notes.SelStart=Len(Notes.Value)

? How to have the cursor moved to the center part. If the contents
consists of 30 lines, it should move to line 15. For 40 lines, to line
20 etc.

Bart
Acc 2003

'something like this may get you close
Private Sub Comments_GotFocus()
Dim colList As New Collection
Dim strVal As Variant
Dim lngPos As Long
Dim lngStart As Long
Dim lngLines As Integer

strVal = Me.Comments

If Not IsNull(strVal) Then
Do While True
lngLines = lngLines + 1
lngPos = InStr(strVal, Chr(13) & Chr(10))
colList.Add lngStart
If lngPos 0 Then
lngStart = lngStart + lngPos + 1
strVal = Mid(strVal, lngPos + 2)
Else
Exit Do
End If
Loop
End If

lngStart = colList(Int(lngLines / 2) + IIf(lngLines Mod 2 = 1, 1, 0))
Me.Comments.SelStart = lngStart

End Sub

Oct 8 '06 #5

P: n/a
Ah, I see the issue. I want to have the requested focus when I push on
a button, I named it cmdCenter. I do not want it under Notes as I do
not want it positioned in center when I focus to Notes in a normal way.
So only aafter a button click.
When I put your script nuder the cmbCenter.GotFocus I get the error I
mentioned before.
How is the script when I put it under a button?

Bart
On Oct 8, 10:10 pm, salad <o...@vinegar.comwrote:
AA Arens wrote:
Hi Salad, thaks for the input.
It is indeed in the right direction, though I get the message:
Run-Time error 2185
Cannot reference a property or method for a control unless control has
focus.
I get the error both when I put your script under GetFocus as Click
procedures.
at
Me.Notes.SelStart = lngStartYes, you need to put the last 2 lines
lngStart = colList(Int(lngLines / 2) + IIf(lngLines Mod 2 = 1, 1, 0))
Me.Comments.SelStart = lngStart
just above the Endif

I put the code in the GotFocus for the memo field. Not sure what you
mean by Click procedures.

Ensure all refs to Comments now reflects Notes since that's the name of
your memo field.
Bart
salad wrote:
>AA Arens wrote:
>>I have a Notes block and have to buttons to have the cusror moved to
the top as well as the bottom of the contents.
>>Here is the VB of the buttons:
>>To top:
Notes.SelStart=0
>>To bottom:
Notes.SetFocus
Notes.SelStart=Len(Notes.Value)
>>? How to have the cursor moved to the center part. If the contents
consists of 30 lines, it should move to line 15. For 40 lines, to line
20 etc.
>>Bart
Acc 2003
>'something like this may get you close
Private Sub Comments_GotFocus()
Dim colList As New Collection
Dim strVal As Variant
Dim lngPos As Long
Dim lngStart As Long
Dim lngLines As Integer
strVal = Me.Comments
If Not IsNull(strVal) Then
Do While True
lngLines = lngLines + 1
lngPos = InStr(strVal, Chr(13) & Chr(10))
colList.Add lngStart
If lngPos 0 Then
lngStart = lngStart + lngPos + 1
strVal = Mid(strVal, lngPos + 2)
Else
Exit Do
End If
Loop
End If
lngStart = colList(Int(lngLines / 2) + IIf(lngLines Mod 2 = 1, 1, 0))
Me.Comments.SelStart = lngStart
>End Sub
Oct 9 '06 #6

P: n/a
"AA Arens" <ba***********@gmail.comwrote in
news:11**********************@b28g2000cwb.googlegr oups.com:
Ah, I see the issue. I want to have the requested focus when I
push on a button, I named it cmdCenter. I do not want it under
Notes as I do not want it positioned in center when I focus to
Notes in a normal way. So only aafter a button click.
When I put your script nuder the cmbCenter.GotFocus I get the
error I mentioned before.
How is the script when I put it under a button?

Bart
modify the last lines of the function by insertoing a .setfocus
just before setting the .selstart property of comments
>>lngStart = colList(Int(lngLines / 2) _
+ IIf(lngLines Mod 2 = 1, 1, 0))
me.Comments.setfocus '<==== new statement
>>Me.Comments.SelStart = lngStart

End Sub

--
Bob Quintal

PA is y I've altered my email address.

--
Posted via a free Usenet account from http://www.teranews.com

Oct 9 '06 #7

P: n/a
Thanks all, it works fine!

On Oct 9, 7:57 pm, Bob Quintal <rquin...@sPAmpatico.cawrote:
"AAArens" <bartvandon...@gmail.comwrote innews:11**********************@b28g2000cwb.google groups.com:
Ah, I see the issue. I want to have the requested focus when I
push on a button, I named it cmdCenter. I do not want it under
Notes as I do not want it positioned in center when I focus to
Notes in a normal way. So only aafter a button click.
When I put your script nuder the cmbCenter.GotFocus I get the
error I mentioned before.
How is the script when I put it under a button?
Bartmodify the last lines of the function by insertoing a .setfocus
just before setting the .selstart property of comments
>lngStart = colList(Int(lngLines / 2) _ + IIf(lngLines Mod 2 = 1, 1, 0))
me.Comments.setfocus '<==== new statement
>Me.Comments.SelStart = lngStart
>End Sub--
Bob Quintal

PA is y I've altered my email address.

--
Posted via a free Usenet account fromhttp://www.teranews.com
Oct 11 '06 #8

P: n/a
AA Arens wrote:
Thanks all, it works fine!
Cool.
Oct 11 '06 #9

This discussion thread is closed

Replies have been disabled for this discussion.