Results 1 to 13 of 13
  1. #1
    Join Date
    Nov 2007
    Location
    Adelaide, South Australia
    Posts
    4,049

    Unanswered: Some Aussie rambling or something (was "Ummm... F2 without F2?")

    Sorry I have no idea what to name this topic. Mods, feel free to enter a better one

    I am having a brain lockup. I know there is a fairly easy way to do this, but I can't remember how to do it.

    All I want to do is move the focus to a comments field and put the cursor in it after the last character, ready for the user to start typing their comment.

    I have a command button, which adds the username and date to a comments field, then a colon, then the code sets the focus to the field, but the entire field is selected. I can get what I want by SendKeys "{F2}" etc, but I detest SendKeys.

    What's the way to do this without SendKeys?

    Thanks very much in advance
    Owner and Manager of
    CypherBYTE, Microsoft Access Development Specialists.
    Microsoft Access MCP.
    And all around nice guy!


    "Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
    "...teach a man to code and he'll be frustrated for life! " -- georgev

  2. #2
    Join Date
    Nov 2007
    Location
    Adelaide, South Australia
    Posts
    4,049
    Try this:

    Me.Comments.SelStart = Len(Me.Comments)
    Owner and Manager of
    CypherBYTE, Microsoft Access Development Specialists.
    Microsoft Access MCP.
    And all around nice guy!


    "Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
    "...teach a man to code and he'll be frustrated for life! " -- georgev

  3. #3
    Join Date
    Nov 2007
    Location
    Adelaide, South Australia
    Posts
    4,049
    Hey that's awesome, thanks, it works perfectly

    You're a legend!
    Owner and Manager of
    CypherBYTE, Microsoft Access Development Specialists.
    Microsoft Access MCP.
    And all around nice guy!


    "Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
    "...teach a man to code and he'll be frustrated for life! " -- georgev

  4. #4
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    Many "comments" fields are defined as Memo Field Datatypes. If this is true for yours, you need to be aware that SelStart takes an Integer as an argument (which means it is limited to 32,767 characters) but a Memo Field can hold twice that many characters (actually 4 times that, I understand, if the data is entered via code) so you have to be careful using SelStart with these fields. Setting SelStart to a value greater than 32767 will cause Access to throw an error, so you should test it's length and if Len(YourMemoField) > 32767 set it to 32767, which would at least get you a whole lot closer to the end of the data.

    Code:
    If Len(YourMemoField) > 32767 Then 
      YourMemoField.SelStart =  32767
    Else
      YourMemoField.SelStart =  Len(YourMemoField)
    End If
    Hope this helps!

    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  5. #5
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    There is also an option on the keyboard tab in Tools --> Options.

    Have a nice day!

  6. #6
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    True, if you want this behavior to be the default for all fields in all databases run from your copy of Access. If the database is to be run on other machines, they too, will have to have the Option set.

    Tools - Options - Keyboard - Behavior on entering Field

    The advantage of using the code is that you only affect this single field on this single database and it will do this on other machines, regardless of how the option set on those machines.
    Hope this helps!

    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  7. #7
    Join Date
    Apr 2004
    Location
    Sydney Australia
    Posts
    369
    I use this following the opening of a form with memo field

    Forms![ProspectNotes]!ActdateComments.SetFocus

    Forms![ProspectNotes]!ActdateComments.SelStart = Len(Forms![ProspectNotes]!ActdateComments.Text)

    Forms![ProspectNotes]!ActdateComments.SelLength = 0

  8. #8
    Join Date
    Nov 2007
    Location
    Adelaide, South Australia
    Posts
    4,049
    Thanks for the topic change modz

    And thanks for the tips guys! Interestingly, my comments field is a memo, so if SelStart takes only an integer, there may one day be a problem in the error being thrown, but that error is truly not anticipated. The data would be lucky to reach 5,000 characters max over the entire recordset, so it should suffice for the immediate need.

    But what do you do if you wanted to do with with a 40,000 character field? Would you have to resort to SendKeys?
    Owner and Manager of
    CypherBYTE, Microsoft Access Development Specialists.
    Microsoft Access MCP.
    And all around nice guy!


    "Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
    "...teach a man to code and he'll be frustrated for life! " -- georgev

  9. #9
    Join Date
    Apr 2004
    Location
    Sydney Australia
    Posts
    369
    I just pasted a Word doc in which had 43,000 characters and that produced Overflow debug on this line

    Forms![ProspectNotes]!ActdateComments.SelStart = Len(Forms![ProspectNotes]!ActdateComments.Text)

    I cut it back to what was 23,000 characters and all worked OK. So somewhere between 23000 and 43000.

    Those character counts include spaces.

  10. #10
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    Quote Originally Posted by StarTrekker
    Thanks for the topic change modz
    I live to serve
    Testimonial:
    pootle flump
    ur codings are working excelent.

  11. #11
    Join Date
    Nov 2007
    Location
    Adelaide, South Australia
    Posts
    4,049
    32,768 if memory serves... that's the limit for integers.

    2
    4
    8
    16
    32
    64
    128
    256
    512
    1024
    2048
    4096
    8192
    16384
    32768, yes, that's the number
    Owner and Manager of
    CypherBYTE, Microsoft Access Development Specialists.
    Microsoft Access MCP.
    And all around nice guy!


    "Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
    "...teach a man to code and he'll be frustrated for life! " -- georgev

  12. #12
    Join Date
    Apr 2004
    Location
    Sydney Australia
    Posts
    369
    I found this but have not tried it. Scroll down a few posts to Lebans

    SelStart in Large Textbox - bytes

    Amazing that in a simple macro Keystrokes {F2} and Wait Yes will do the trick.

    Converting the macro to SendKeys "{F2}", True worked.

    Maybe the best way is to have an IF and >32767 etc.

  13. #13
    Join Date
    Nov 2007
    Location
    Adelaide, South Australia
    Posts
    4,049
    True enough, but it's a stupid limitation. It means there is no way to put the cursor at position 40,000 of a 50,000 charactered string. Not that you'd ever really need to do it, but it is a limitation imposed by the argument being an integer.

    Thanks for finding the posted link Mike, if I ever find that I need to do something so weird, I will try it out.
    Owner and Manager of
    CypherBYTE, Microsoft Access Development Specialists.
    Microsoft Access MCP.
    And all around nice guy!


    "Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
    "...teach a man to code and he'll be frustrated for life! " -- georgev

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •