Results 1 to 6 of 6
  1. #1
    virencm is offline Novice
    Windows 7 32bit Access 2016
    Join Date
    Jun 2019
    Posts
    7

    VBA code to display date at the start of field.

    Hi Guys,

    I need help with VBA code for this one please.

    I have a button above a memo field. on click event of this button I need the cursor to go the the start of the memo field and hit enter so that the user can append comments at the start of the field

    The code i have come up with so far is below:



    Code:
    me.comments.setfocus
    me.comments.selstart =0
    me.comments.value = me.comments .value & vbnewline & left(Date,5) & " - "
    The above code is supposed to start at position 0 of the comment box, hit enter and display a date so the user can start typing a note.

    Instead the code finds the last word in the comments box, hits enter and displays date at the end.

    Can someone please help with the code to display the date at position 0?

    Hope this makes sense.

    Thanks
    V

  2. #2
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2016
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,544
    Perhaps:
    me.comments = left(Date,5) & " - " & vbnewline & me.comments
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  3. #3
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    Or you have the equation backwards?
    me.comments = vbnewline & left(Date,5) & " - " & me.comments
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  4. #4
    orange's Avatar
    orange is online now Moderator
    Windows 10 Access 2016
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    If you are planning to have multiple comments within this memo field -each with its own date - then, I suggest you consider a separate table for comments. This will make it much easier to sort and report. I've seen many people use the memo field concatenation approach and simulate a table; then have issues with sorting etc. Often saying, yes - it should have been a real table.
    Good luck with your project.

  5. #5
    virencm is offline Novice
    Windows 7 32bit Access 2016
    Join Date
    Jun 2019
    Posts
    7
    Thank you all.

    Micron, Your suggestion worked. I had the equation backwards.

    Many Thanks

  6. #6
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    FWIW I agree with orange. Mash all the comments together and you'll probably be back asking how to report by date. Each comment should be treated like a record, because that's what it is.

    Otherwise, glad I could help.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 5
    Last Post: 08-15-2019, 03:46 PM
  2. Replies: 1
    Last Post: 10-12-2017, 06:12 PM
  3. Replies: 6
    Last Post: 03-02-2016, 12:58 PM
  4. Replies: 20
    Last Post: 01-13-2015, 02:23 PM
  5. Replies: 15
    Last Post: 04-06-2012, 10:57 AM

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