Go Back   Access World Forums > Microsoft Access Discussion > Forms

 
Reply
 
Thread Tools Rate Thread Display Modes
Old 12-02-2014, 10:26 AM   #1
easykey
Newly Registered User
 
Join Date: Dec 2014
Posts: 6
Thanks: 1
Thanked 0 Times in 0 Posts
easykey is on a distinguished road
place cursor at end of first line in memo field

I have created a button that takes the contents of a memo field and adds a new line of text at the top with the date, time and initials of staff member. So far, so good...

However I want it to end with the cursor ready at the end of the first line (to type the note) The following code does everything but ends by putting the cursor right at the end of all of the text in the memo field (instead of the end of the first line):

Code:
Private Sub Command59_Click()
Me.Note = Format(Now, "d mmm yyyy hh:nn") & " - " & "(" & DLookup("[login]", "logintable") & ") " & Chr(13) & Chr(10) & Me.Note
    Me.Note.SetFocus
    Me.Note.SelStart = Len(Me.Note)
    Me.Note.SelLength = 0
End Sub

easykey is offline   Reply With Quote
Old 12-02-2014, 12:02 PM   #2
AccessBlaster
.
 
Join Date: May 2010
Posts: 1,205
Thanks: 29
Thanked 276 Times in 263 Posts
AccessBlaster has a spectacular aura about AccessBlaster has a spectacular aura about
Re: place cursor at end of first line in memo field

Code:
Me.Note.SetFocus
File > Options > Client Settings > Editing

Attached Images
File Type: png Options.png (72.8 KB, 552 views)
AccessBlaster is offline   Reply With Quote
Old 12-02-2014, 01:39 PM   #3
easykey
Newly Registered User
 
Join Date: Dec 2014
Posts: 6
Thanks: 1
Thanked 0 Times in 0 Posts
easykey is on a distinguished road
Re: place cursor at end of first line in memo field

Thanks AccessBlaster but that doesn't really help me.

I have a Memo field called Notes that can hold a few lines of text I need it to do the following:
1. Copy all of the current contents (this works)
2. Paste all of the contents inserting a new line of text at the top (this works)
3. Put today's date and time plus the staff initials on that new top line (this works)
4. Place the cursor at the end of the first line - ready to type appending text to the end of the top line but above any earlier lines (this does not work) the code above puts the cursor at the very end of all lines of text in the memo box.

This second attempt kinda works (but only if steps 1, 2 and 3 creates exactly the right number of characters) the problem is that the number varies.

Code:
Private Sub Command59_Click()
Me.Note = Format(Now, "d mmm yyyy hh:nn") & " - " & "(" & DLookup("[login]", "logintable") & ") " & Chr(13) & Chr(10) & Me.Note
    Me.Note.SetFocus
    Me.Note.SelStart = 25
    Me.Note.SelLength = 0
End Sub
I guess I could do with a way of counting the number of characters created in steps 1, 2 and 3.

Or maybe a way of counting the number of characters up to the first line break?

easykey is offline   Reply With Quote
Old 12-02-2014, 05:49 PM   #4
AccessBlaster
.
 
Join Date: May 2010
Posts: 1,205
Thanks: 29
Thanked 276 Times in 263 Posts
AccessBlaster has a spectacular aura about AccessBlaster has a spectacular aura about
Re: place cursor at end of first line in memo field

How would you define the end of the first line? Is it a period? If so maybe the Instr Function will help.
AccessBlaster is offline   Reply With Quote
Old 12-02-2014, 08:48 PM   #5
MarkK
Super Moderator
 
MarkK's Avatar
 
Join Date: Mar 2004
Location: Vancouver BC
Posts: 7,761
Thanks: 10
Thanked 1,290 Times in 1,227 Posts
MarkK is a name known to all MarkK is a name known to all MarkK is a name known to all MarkK is a name known to all MarkK is a name known to all MarkK is a name known to all
You can assign the first line to a variable, then insert it, then check the length of it and advance the insertion point . . .
Code:
Private Sub Command59_Click()
    Dim tmp As String
    tmp = Format(Now, "d mmm yyyy hh:nn") & " - " & "(" & DLookup("[login]", "logintable") & ") " & vbCrLf
    Me.note = tmp & Me.note
    Me.note.SetFocus
    Me.note.SelStart = Len(tmp)
    Me.note.SelLength = 0
End Sub
You can also seach for chr(13) & chr(10), which is the same as the VBA constant vbCrLf.
Code:
    Me.note.SelStart = InStr(1, Me.Note, vbCrLf)
__________________
formerly known as lagbolt | Windows 10 | Access 2010 | Visual Studio 2013 | "Institutions have a vested interest in perpetuating the problems to which they are the solution." - Clay Shirky
MarkK is offline   Reply With Quote
The Following User Says Thank You to MarkK For This Useful Post:
easykey (12-03-2014)
Old 12-03-2014, 01:12 AM   #6
easykey
Newly Registered User
 
Join Date: Dec 2014
Posts: 6
Thanks: 1
Thanked 0 Times in 0 Posts
easykey is on a distinguished road
Re: place cursor at end of first line in memo field

Brilliant! It needed a slight adjustment as when I start typing where the cursor was placed it pre-pended it to the beginning of the second line.

So here is the finished code that works:

Code:
Private Sub Command83_Click()
Me.Note = Format(Now, "d mmm yyyy hh:nn") & " - " & "(" & DLookup("[login]", "logintable") & ") " & Chr(13) & Chr(10) & Me.Note
    Me.Note.SetFocus
    Me.Note.SelStart = InStr(1, Me.Note, vbCrLf) - 1
    Me.Note.SelLength = 0
End Sub
Thank you so much
easykey is offline   Reply With Quote
Old 12-03-2014, 08:01 AM   #7
MarkK
Super Moderator
 
MarkK's Avatar
 
Join Date: Mar 2004
Location: Vancouver BC
Posts: 7,761
Thanks: 10
Thanked 1,290 Times in 1,227 Posts
MarkK is a name known to all MarkK is a name known to all MarkK is a name known to all MarkK is a name known to all MarkK is a name known to all MarkK is a name known to all
You're welcome


__________________
formerly known as lagbolt | Windows 10 | Access 2010 | Visual Studio 2013 | "Institutions have a vested interest in perpetuating the problems to which they are the solution." - Clay Shirky
MarkK is offline   Reply With Quote
Reply

Tags
cursor , field , memo box

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Help Set Cursor in Memo Field? joaompc Modules & VBA 2 12-11-2012 07:27 AM
Subform unable to use mouse to place cursor in field thr33xx Forms 1 05-11-2011 04:02 PM
Memo Field-Cursor moves to first line when entering text Ray Stantz Forms 3 07-16-2009 06:27 AM
How to place a return in a memo field muppetmad Modules & VBA 1 03-20-2006 12:34 PM
Memo Field new Line on Tab MarionD Forms 2 02-04-2003 10:45 AM




All times are GMT -8. The time now is 01:55 AM.


Microsoft Access Help
General
Tables
Queries
Forms
Reports
Macros
Modules & VBA
Theory & Practice
Access FAQs
Code Repository
Sample Databases
Video Tutorials

Featured Forum post


Sponsored Links


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
(c) copyright 2017 Access World