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

Retain cursor position in Memo field, when changing to another field 1

Status
Not open for further replies.

ACFeddes

Programmer
Jun 18, 2007
11
NL
Hello,
I'm having two memo fields beside each other for translating purposes. When I scroll down the text in Memo 1 to see what I want to translate, then move to Memo 2 to actually translate the text, Memo 1 field 'jumps' back to the top of the text.

Is there anyway to retain (hold on) to the previous windows position when switching between fields?

Greetings,
ACF
 
This worked for me
Code:
Option Compare Database
Option Explicit
Dim intPosOne As Integer
Dim intPosTwo As Integer

Private Sub Form_Current()
  intPosOne = 0
  intPosTwo = 0
End Sub

Private Sub memoOne_GotFocus()
  Me.memoOne.SelStart = intPosOne
End Sub

Private Sub memoOne_LostFocus()
  intPosOne = Me.memoOne.SelStart
End Sub

Private Sub memoTwo_LostFocus()
  intPosTwo = Me.memoTwo.SelStart
End Sub
Private Sub memoTwo_GotFocus()
  Me.memoTwo.SelStart = intPosTwo
End Sub
 
Hello MajP,
that does work to some extend. When I'm switching field, it still moves back to the top. When I go back (GetFocus) on Field 1, it will actually go back to where the cursur was - so that works fine.

But for translating, I'd like the cursor and the place in the text to remain static, whilst I go to the other field, so I can translate. When I go back to Field 1 - only to scroll the text down, I'd like the same to happen to Field 2.

If you have any further clue, I'd appreciate it.

ACF
 
How are ya ACFeddes . . .

If I understand you correctly your scrolling Memo1 ([blue]not actually putting the cursor in memo1[/blue]) while in Memo2 you are?


Calvin.gif
See Ya! . . . . . .

Be sure to see FAQ219-2884:
 
Hello Mr. AceMan,
Actually I'll do both - either write in Memo1 or scroll it down. I'd like the screen to 'freeze' when I shift focus to Memo2.

Can you help?

Greetings,
ACF
 
ACFeddes . . .

This is a very tricky situation as access needs a starting point in order to set the cursor position. This is not provided by scrolling alone and is the reason it defaults back to the beginning of the memo.

The [blue]On Click[/blue] event would do nicely here but you'd have to click the mouse to set the cursor if its not already where it should be.

As for scrolling only, I'm currently searching for an [blue]API[/blue] that can return scroll position. I'll let you know later on today (I'm at work) . . .

Calvin.gif
See Ya! . . . . . .

Be sure to see FAQ219-2884:
 
Now that I understand what you are doing there is an easy trick. Instead of selecting a standard Access Text Box look under the "More Controls" icon. It looks like a crossed wrench and hammer. Select a MS Forms 2.X Text box. Ensure that you set the "Multi Line" to true and "Scroll Bar" to Vertical. This has the behavior that you want. Both windows stay still. You may also try using a Rich Text box.
 
Hello MajP,
thank you for the good advice - that works great, although it reduces the font size to default.

I'm starting to use Access 2007, where I have RTF applied to my memo fields. If I then use a MS Forms 2.X Text box, it will show all the HTML characters.

I'm therefore much interested in what RTF box you would recommend?
I've tried to add Active Control: Microsoft Rich Textbox Control 6.0(SP4), but this active controls was not supported in Access.
I also tried "RichText BoxEx.ctlRichtEdit", but it gave another error saying I had no rights for this active control.

Is there anyway to fix this or can you recommend another one?

Grateful for your help so far.

Greetings,
ACF
 
One thing about non-access controls is that sometimes they do not expose all of their properties. I do not understand that, maybe someone smart on this site can answer that question. If you use either the intellisensense or the property window you will not see any way to change the controls font or size. So I took some guesses at some property names and I was able to modify font and size.
Code:
Private Sub Form_Open(Cancel As Integer)
  Me.TextBox6.FontSize = 25
  Me.TextBox6.FontWeight = 10
  Me.TextBox6.FontName = "Courier"
  Me.TextBox6.FontUnderline = True
  Me.TextBox6.FontBold = True
End Sub

So play with those properties in the Form_Open event.

Registering Active X controls is sometimes problematic. You can use the search feature and FAQs on this site to get information on doing that. I always have to play around with it to get it to register correctly, and you may have issues between different computers. Portability is an issue. The correct choice is the Rich Textbox Control 6.0, but for ease I would stick with this text box and play with the code I gave you. The Rich Textbox, however, has a lot of capability so you may want to explore it more.
 
Wow, that works great too.

Thank you very much.

I'll play around with the registry some other time - already tried a bit, but to no avail.

Another question, seeing we've already come this far, related to my other post - - when I select the text in one memo field, I can now with the MouseUp procedure event copy Selected Text to the clipboard using this code:

Code:
Private Sub Memo_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
'If MsgBox("Copy?", vbYesNo) = vbYes Then
   
   Call ClipBoard_SetData(Memo.SelText)
   

' End If
End Sub

Would there be a way to also apply some formatting to this selected text, for example red font & bold. as / before it is being copied to the clipboard (I'm starting to work with Access 2007, which has RTF).?

I can only apply the selText with the MouseUp event and not to a command button as Access tells me the SelText can not be applied when the focus on a field is lost.
Is there a way around that?

Greetings,
ACF
 
1) Yes with a richtext box in A2007 you can apply formatting to part of the text, something you could not do before with any other text box. See link:
Kind of like a miny word processor

2) The work around it to use a public variable and the lostfocus event of the textbox to save the selection.

Code:
Option Compare Database
Option Explicit

Dim strSelection As String

Private Sub TextBox6_LostFocus()
  strSelection = TextBox6.SelText
End Sub

Private Sub Command9_Click()
  If MsgBox("Copy?", vbYesNo) = vbYes Then
    Call ClipBoard_SetData(Memo.SelText)
   End If
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top