Page 2 of 2 FirstFirst 12
Results 16 to 28 of 28
  1. #16
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,954
    True but that's because I thought you wanted that...
    I would also scrap the SendIeys items and do everything from an event procedure
    For example, instead of the previous event procedure, you could add this to the On Enter event of the ClinicalNotes control



    Code:
    Private Sub ClinicalNotes_Enter()
    
    Me.ClinicalNotes = Me.ClinicalNotes & vbNewLine & vbNewLine & Now & " " & Me.CatName
    
    End Sub
    Create the procedure in the same way as before.
    Play around with this if needed to get the result you want.
    You could also try a different event like On Key Down
    Event procedures are FAR more powerful than macros and very quickly become easier to work with.

    Good luck with your project
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  2. #17
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,643
    With your existing db that you posted on the other thread place this code under the DateStamp command button.
    Use the event procedure method that Colin posted
    Code:
    Private Sub DateTimeStamp_Click()
    
        Me.ClinicalNotes = Me.ClinicalNotes & vbNewLine & Format(Now, "dd-mm-yy_@_h:nn:ss") & " " & Me.CatName & vbNewLine
    
    
        Me.ClinicalNotes.SetFocus
    
    
        Me.ClinicalNotes.SelStart = Len(Me.ClinicalNotes)
    
    
    End Sub
    I also just noticed that in your module declarations you only have Option Explicit declared. you should probably have
    Code:
    Option Compare Database
    Option Explicit
    The default option compare is binary which means A<>a , etc.

  3. #18
    Cookie is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Sep 2020
    Posts
    45
    Thanks Isladogs.

    Realistically, and admittedly, this works better than the SendKeys approach, the only reservation (I have) so far is that Sendkeys allowed insertion of the new date and time line at the top of the existing text.

    Having put the procedure together as suggested by you and playing around with it, I found the date and time and appended CatName (a step in the right direction, thank you again!) are added to the end of the existing text field without the field being scrolled to the insertion point after, and to the left, for the user to start entering new observations. i.e. the cursor isn't where the user can start typing.

    Here are the two procedures I am experimenting with:

    Private Sub ClinicalNotes_Enter()
    Me.ClinicalNotes = Me.ClinicalNotes & vbNewLine & vbNewLine & Now & " " & Me.CatName & vbNewLine & vbNewLine
    End Sub




    Private Sub Command188_Click()
    Me.ClinicalNotes = Me.ClinicalNotes & vbNewLine & vbNewLine & Now & " " & Me.CatName & vbNewLine & vbNewLine
    End Sub


    When the procedure works on the Entry event, the text is inserted 3 lines down and cursor moves 2 lines down under the that text provided the mouse is clicked below the proposed 5 lines in the procedure.

    When the procedure works on the Command188 click event (shown above), the cursor disappears after the date and time and CatName text is pasted.

    So, when the mouse is clicked in the text box again, unfortunately it causes the Entry event to be executed again.

    I commented out the Entry event to see what would happen just using command188 button.

    I find I get more reliable behaviour but I still have to scroll down to find the current date and time entry so I can start typing underneath it.

    I had read here: https://www.pcreview.co.uk/threads/p...field.1149278/ that I could use an adaptation of
    a GotFocus event

    Suggested was: Me!FieldName.SelStart = Me!FieldName.SelLength


    I guess that makes the adptation to become

    Me!ClinicalNotes.SelStart = Me!ClinicalNotes.SelLength

    However, I cannot get that to work.

  4. #19
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,643
    DELETED as I realized you want the new entry at top of field

  5. #20
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,643
    This code will place the new entries at the top. Note that I'm using the command button "DateTimeStamp"

    Code:
    Private Sub DateTimeStamp_Click()
    
    
        Me.ClinicalNotes = Format(Now, "dd-mm-yy_@_h:nn:ss") & " " & Me.CatName & vbNewLine & vbNewLine & vbNewLine & Me.ClinicalNotes
        
        Me.ClinicalNotes.SetFocus
    
    
        Me.ClinicalNotes.SelStart = Len(Format(Now, "dd-mm-yy_@_h:nn:ss") & " " & Me.CatName & vbNewLine)
        
    
    
    End Sub
    Click image for larger version. 

Name:	cookie.png 
Views:	15 
Size:	18.9 KB 
ID:	42951

    to break it down:
    The first line takes the timestamp and cat name and concatenates them with 3 line feeds and the existing contents of the field.
    the second line sets the focus to the control which is required to use the selstart method.
    the third line places the cursor at the length of the timestamp, the cat name, and one line feed.

  6. #21
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,954
    As I was going to make similar points to those by @moke123, I'll drop out of the thread and leave you in moke's capable hands
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  7. #22
    Cookie is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Sep 2020
    Posts
    45

    Purrfect support!

    Quote Originally Posted by isladogs View Post
    As I was going to make similar points to those by @moke123, I'll drop out of the thread and leave you in moke's capable hands
    I think it's great that we got there in the end.

    The final code put down (Isladogs and Moke123 & thanks to all really):

    Private Sub Command188_Click()
    Me.ClinicalNotes = Me.ClinicalNotes & vbNewLine & vbNewLine & Format(Now, "dd-mm-yy_@_h:nn:ss") & " " & Me.CatName & vbNewLine
    Me.ClinicalNotes.SetFocus
    Me.ClinicalNotes.SelStart = Len(Me.ClinicalNotes)
    End Sub


  8. #23
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,643
    If you want to get fancy and indent the first line of the notes you can substitute in this line
    Code:
        Me.ClinicalNotes = Me.ClinicalNotes & vbNewLine & vbNewLine & Format(Now, "dd-mm-yy_@_h:nn:ss") & " " & Me.CatName & vbNewLine & Space(5)
    Col and I were happy to help
    Good luck with your project.

  9. #24
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,954
    Or use vbTab instead of Space(5) ..... except vbTab indents by 4 characters ....
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  10. #25
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,643
    We may have to start a new thread Colin. The APA style manual specifically states 5 spaces or 1/2 inch for an indent. They did however change the 2 space minimum after a period to one space in the 2019 revisions.

  11. #26
    Cookie is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Sep 2020
    Posts
    45
    Thank you Isladogs and Moke 123,

    I like the way you guys collaborate! I have incorporated that suggestion and it looks neat!

  12. #27
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,954
    You're welcome. For the benefit of anyone reading this thread in the future, please post your final code
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  13. #28
    Cookie is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Sep 2020
    Posts
    45
    Thank you, I modified the code a tad to add an attendant's name.

    This code works with the Date and Time Punch button to insert the Date, Time, Cat's Name and Attendant's name. The attendant's name is just typed into a local text field.

    The cursor start position is indented a couple of lines under the date and time field.

    Private Sub Command188_Click()
    Me.ClinicalNotes = Me.ClinicalNotes & vbNewLine & vbNewLine & Now() & " " & Me.CatName & " [Attendant: " & Me.Attendant & "]" & vbNewLine & vbNewLine & Space(5)
    'Me.ClinicalNotes = Me.ClinicalNotes & vbNewLine & vbNewLine & Format(Now, "dd-mm-yy_@_h:nn:ss") & " " & Me.CatName & vbNewLine & Space(5)'
    Me.ClinicalNotes.SetFocus
    Me.ClinicalNotes.SelStart = Len(Me.ClinicalNotes)

    End Sub

Page 2 of 2 FirstFirst 12
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 8
    Last Post: 09-06-2020, 09:07 PM
  2. Access from Office 10 will not work in Office 365
    By Majestic Eagle in forum Access
    Replies: 3
    Last Post: 01-03-2017, 03:49 AM
  3. Replies: 6
    Last Post: 12-09-2015, 01:17 PM
  4. Using the SendKeys action in a Macro
    By john134 in forum Programming
    Replies: 5
    Last Post: 05-27-2014, 01:54 PM
  5. Replies: 20
    Last Post: 10-25-2013, 06:16 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums