Results 1 to 10 of 10
  1. #1
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496

    Preventing whole selection in a memo field

    When the user enters the memo field on a form I have it selects all the text.

    This is dangerous because they might overwrite all the contents of that memo field with a keystroke.

    How do I prevent this from happening?

  2. #2
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    'Behavior Entering Field' is a user defined/controlled option and if the 'Select Entire Field' option is chosen, by any user, that's the behavior they'll get, and yes, it is dangerous! What you can do, to prevent this on all users, is something like this, replacing all instances of MyMemoField with the actual name of your Memo Field Textbox:
    Code:
    Private Sub MyMemoField_Click()
      If IsNull(Me.MyMemoField.Value) Then
       Me.MyMemoField.SelStart = 0
      End If
      
      If Not IsNull(Me.MyMemoField.Value) Then
        If Len(Me.MyMemoField.Value) < 32767 Then
          Me.MyMemoField.SelStart = Len(Me.MyMemoField.Value)
        Else
          Me.MyMemoField.SelStart = 0
       End If
      End If
    End Sub
    
    Private Sub MyMemoField_GotFocus()
      If IsNull(Me.MyMemoField.Value) Then
       Me.MyMemoField.SelStart = 0
      End If
      
      If Not IsNull(Me.MyMemoField.Value) Then
        If Len(Me.MyMemoField.Value) < 32767 Then
          Me.MyMemoField.SelStart = Len(Me.MyMemoField.Value)
        Else
          Me.MyMemoField.SelStart = 0
       End If
      End If
    End Sub

    This will set the cursor to the end of the data, until it reaches 32767 characters, at which time it will place the cursor at 32767 characters. The used SelStart takes an Integer as an argument, and 32767 is the limit for Integers, so you cannot set it beyond there. But let's be honest, it's seldom that a Memo Field is actually going to surpass that limit!

    Linq ;0)>

  3. #3
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    Quote Originally Posted by Missinglinq View Post
    'Behavior Entering Field' is a user defined/controlled option and if the 'Select Entire Field' option is chosen, by any user, that's the behavior they'll get, and yes, it is dangerous! What you can do, to prevent this on all users, is something like this, replacing all instances of MyMemoField with the actual name of your Memo Field Textbox:
    Code:
    Private Sub MyMemoField_Click()
      If IsNull(Me.MyMemoField.Value) Then
       Me.MyMemoField.SelStart = 0
      End If
      
      If Not IsNull(Me.MyMemoField.Value) Then
        If Len(Me.MyMemoField.Value) < 32767 Then
          Me.MyMemoField.SelStart = Len(Me.MyMemoField.Value)
        Else
          Me.MyMemoField.SelStart = 0
       End If
      End If
    End Sub
    
    Private Sub MyMemoField_GotFocus()
      If IsNull(Me.MyMemoField.Value) Then
       Me.MyMemoField.SelStart = 0
      End If
      
      If Not IsNull(Me.MyMemoField.Value) Then
        If Len(Me.MyMemoField.Value) < 32767 Then
          Me.MyMemoField.SelStart = Len(Me.MyMemoField.Value)
        Else
          Me.MyMemoField.SelStart = 0
       End If
      End If
    End Sub

    This will set the cursor to the end of the data, until it reaches 32767 characters, at which time it will place the cursor at 32767 characters. The used SelStart takes an Integer as an argument, and 32767 is the limit for Integers, so you cannot set it beyond there. But let's be honest, it's seldom that a Memo Field is actually going to surpass that limit!

    Linq ;0)>
    I'm thinking this is a windows control option? If so how do I get around it? Or is it a setting in access? If so I have a problem because I am using runtime and will have to implement your code.

  4. #4
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    Note: runtime does not have those options to customize the client

  5. #5
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Have never used RunTime so have no idea vis-à-vis setting options. It is an Access Option, found under Options - Advanced - Behavior Entering Field. But using the code I gave will control the behavior of the Memo Field Control, within the limitation I gave you.

    Linq ;0)>

  6. #6
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    Private Sub Form_Load()Application.SetOption "Behavior Entering Field", 1
    End Sub
    I solved it. You use this on the very first form that is loaded. It then saves the setting for the rest of the forms unless otherwise specified. This is the only way I can see it possible for runtime.

  7. #7
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Glad you got it knocked! Have you actually tested it? I ask because many times when you set the Application Options (through code or on the Ribbon) they don't actually kick in until Access is closed then re-opened. Even so, that would only leave you at risk the first time a user opened the db. Also would be interesting to know if the Access Gnomes consider setting the App Options to be 'design changes,' which are verboden in RunTime, if I remember correctly; but as I said, I've never really used RunTime.

    Linq ;0)>

  8. #8
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    Quote Originally Posted by Missinglinq View Post
    Glad you got it knocked! Have you actually tested it? I ask because many times when you set the Application Options (through code or on the Ribbon) they don't actually kick in until Access is closed then re-opened. Even so, that would only leave you at risk the first time a user opened the db. Also would be interesting to know if the Access Gnomes consider setting the App Options to be 'design changes,' which are verboden in RunTime, if I remember correctly; but as I said, I've never really used RunTime.

    Linq ;0)>
    Yeah it works, all the staff have been using their front ends all day today without a hitch. I thought about to what extent you can bring back options through runtime (contextual menu for right click for example) but haven't played around with it thus far.

    I am still trying to work out popup to front for forms but with print options. If I remove popup I get back the print options but then the forms open behind the previous form.

    I do like using vba to set that option - even if they have Access in the full they are forced by default to use the option I choose (great if someone forgets to adjust their settings).

  9. #9
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows XP Access 2003
    Join Date
    Aug 2013
    Posts
    7,862
    Ruegen,

    I offered a right click menu in the other thread you started. I uploaded a file that can be imported to your accdb and then utilized during RT. There are three menus, including a right click shortcut that can be assigned to Popup/Modal Forms/Reports.

    The code offered in this thread by Missinglinq should work just fine in RT. In fact, RT is all about using VBA to get things done. The code offered in this thread should work just fine in a subroutine for a form. Using .SelStart is usually not something I would put in a Genearal Module as a public function. There is a reason Missinglinq placed .SelStart in two subroutines. It needs to monitor the User's actions and would slow things down as a Public Function.

  10. #10
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    Quote Originally Posted by ItsMe View Post
    Ruegen,

    I offered a right click menu in the other thread you started. I uploaded a file that can be imported to your accdb and then utilized during RT. There are three menus, including a right click shortcut that can be assigned to Popup/Modal Forms/Reports.

    The code offered in this thread by Missinglinq should work just fine in RT. In fact, RT is all about using VBA to get things done. The code offered in this thread should work just fine in a subroutine for a form. Using .SelStart is usually not something I would put in a Genearal Module as a public function. There is a reason Missinglinq placed .SelStart in two subroutines. It needs to monitor the User's actions and would slow things down as a Public Function.
    I'll have a look into that ItsMe - forgive me if I take a while to respond (I'm overwhelmed with work ) usually I don't even like asking for help and I ask 1% on this forum and work the 99% out myself. I will get to it very soon but I thank you kindly for you help.

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

Similar Threads

  1. Replies: 2
    Last Post: 02-28-2013, 10:06 AM
  2. Excel Import field truncation problem (to Access Memo field)
    By jhrBanker in forum Import/Export Data
    Replies: 6
    Last Post: 07-27-2012, 08:52 AM
  3. Change Text field to Memo Field in a Query
    By Yarbz in forum Queries
    Replies: 5
    Last Post: 06-28-2012, 05:24 PM
  4. Replies: 5
    Last Post: 06-19-2012, 10:46 AM
  5. Memo field ?
    By beast_b9 in forum Access
    Replies: 2
    Last Post: 05-26-2010, 08:09 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