Results 1 to 10 of 10
  1. #1
    ScubaBart is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Jul 2024
    Posts
    117

    Adding new line of text to Long Text field w/ VBA

    So, still building on my Apiary / Hive / Inspection application, converting everything over to VBA and it's going pretty well, learning stuff along the way and while I'm not to this point yet, I will be soon.

    When I do certain things with a given Apiary or Hive such as make it in-active or move it, I decided I want to automatically enter a line in the Description / History field which is a Long Text field in each table as needed.

    For instance, if I move a Hive from one Apiary to another, I want to add a new line something like, "Moved from Apiary XYZ on 01/01/2024" (or whatever the date is).


    So, I would be using a pop-up form to complete the move and have it pulling data from the appropriate query that contains all the relevant fields and I'm thinking something like:

    Code:
    Form!Move_Hive!Description.Caption = "Hive moved from Apiary " & [Form]![Move_Hive]![Apiary] & " on " & Format$(Now(), "Short Date") & vbCrLf & [Form]![Move_Hive]![Description]
    Then I would expect to see:

    "Hive moved from Apiary XYZ on 9/12/24
    Blah Blah Blah rest of existing Description"



    Am I anywhere close ? Not sure about the use of the Caption in the first part but am using it for other things like plain text fields and other controls and buttons so figured it was appropriate.

    One thing I am still figuring out is when I need the full path format for controls and when I only need the control name and when I need the brackets and when I don't. So that stuff may be wrong but I think adding it is worse than not when trying it for the first time.

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,555
    You would not use the Caption property, but the Value property, which you can omit, so
    Me.hive = me.hive & me.txtToAdd
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    ScubaBart is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Jul 2024
    Posts
    117
    Quote Originally Posted by Welshgasman View Post
    You would not use the Caption property, but the Value property, which you can omit, so
    Me.hive = me.hive & me.txtToAdd
    Forgot about the Value property. makes sense.

    does the Me prefix essentially take the place of the full Form!.... syntax ?

  4. #4
    Join Date
    May 2018
    Location
    Living in Scotland UK
    Posts
    1,820
    Hi
    I would recommend that instead of adding new lines to a text Control, it would be better to have a table with a unique record to record each change made to a specific Apiary.

  5. #5
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,555
    Quote Originally Posted by ScubaBart View Post
    Forgot about the Value property. makes sense.

    does the Me prefix essentially take the place of the full Form!.... syntax ?
    Yes, but only refers to the object the code is running in Form or Report.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  6. #6
    Micron is online now Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,422
    I'm with anyone who thinks these should be separate records. If nothing else, it can provide a history. Once you start melding comments/events in one field it's very difficult (if possible at all) to segregate them based on anything, such as a time line.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  7. #7
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,555
    I concur, but just responded to the query as asked.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  8. #8
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 11 Office 365
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,879
    The Me. keyword will also invoke intellisense in the form or report module.
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  9. #9
    ScubaBart is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Jul 2024
    Posts
    117
    Thanks for all the input.

    I understand the reasoning behind the suggestions to add a field or separate linked table for "events" like this and it may be that I end up doing that, at least for a couple specific types of 'events' but for a few other parts of my app, it doesn't justify the need for a searchable list of records.

    I will know more as I get into the nitty gritty of those particular aspects and the overall flow of the database. Right now, still converting all the macros to VBA and fine tuning the basic navigation from form to form. Only able to get in a few bits of time here and there.

  10. #10
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,555
    Probably worth doing now.
    That way you could have a date/time when something happened?
    Try and think ahead a few months, not just a few minutes.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

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

Similar Threads

  1. Replies: 7
    Last Post: 12-01-2021, 12:44 PM
  2. Replies: 5
    Last Post: 10-27-2021, 07:11 PM
  3. How can I import long text with line breaks from .XML
    By PeterG in forum Import/Export Data
    Replies: 3
    Last Post: 07-11-2020, 03:54 PM
  4. Replies: 8
    Last Post: 01-07-2020, 12:28 PM
  5. Replies: 24
    Last Post: 03-12-2019, 08:02 PM

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