Page 1 of 3 123 LastLast
Results 1 to 15 of 33
  1. #1
    twgonder is offline Expert
    Windows 10 Access 2021
    Join Date
    Jun 2022
    Location
    Colombia
    Posts
    714

    Move the scollbar in a Form with VBA

    After looking at lots of posts in different forums, I still can't find the API trick to scroll about precisely in a regular form.
    I've taken out all the constants and distilled the API command to its simplest form for testing.

    This is the API declare:
    Public Declare PtrSafe Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As LongPtr, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long

    These three lines are to test moving the scroll bar. The first two work but in the third one I'm trying to precisely position the scroll bar much finer than by a "line", which moves too much.
    Code:
      SendMessage Me.hWnd, 277, 6, 0 'goes to top of the form
      SendMessage Me.hWnd, 277, 1, 0 'goes down one line
      SendMessage Me.hWnd, 277, 5, 9999 'trying to move a precise amount, can't find the trick
    No matter what I enter for the 4th argument in the third line, it scrolls to the top of the form.
    For C++ documentation I see something about a SetScrollInfo, so maybe the 2-4 parameters are wrong for the fine-tuning part.



    I looked at the Lebans idea, some said it doesn't work in newer versions of Access. With Office 365 I can't open the .mdb file to peek.

    Got any ideas for the third?

  2. #2
    jojowhite's Avatar
    jojowhite is offline Competent Performer
    Windows 11 Access 2021
    Join Date
    Jan 2025
    Posts
    434
    you can use SelTop property of the form to position the Vertical scrollbar.
    open TestVerticalScrollbar form on the demo.
    Attached Files Attached Files

  3. #3
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,932
    there is set and get scrollinfo - that sets the scrollbar information and is based on the scrollbar hwnd. With regards Lebans, it still works but the parameters to identify the scrollbar hwnd have changed - if you don't change it, it won't work. The other thing that didn't work (but does in later versions) was scrolling by using the mousewheel rather than the scrollbar. Leabns provided a method for scrolling using the mousewheel

    With regards your objective of scrolling by less than a line (which implies a continuous form), I don't believe it can be done, you can only get that level of fineness for a vertical scrollbar with a single form. - Might be possible using your own scrollbar rather than the windows ones but I doubt it.

    For all of these methods to work, the form needs to have the scrollbar enabled when opened to instantiate the scrollbar object. However once instantiated you can hide the scroll bar and still reference the scrollbar object. Useful for example for traversing an image larger than the image control by using the mouse move event or setting the scroll position to a previously stored value.

    I've attached the Lebans db here (with the parameters updated)
    Attached Files Attached Files

  4. #4
    twgonder is offline Expert
    Windows 10 Access 2021
    Join Date
    Jun 2022
    Location
    Colombia
    Posts
    714
    @jojowhite My bad, I said regular form when I should have said "Single Form". Thanks for the db, I'll have a better look if I need to control Continuous forms the same way.

  5. #5
    twgonder is offline Expert
    Windows 10 Access 2021
    Join Date
    Jun 2022
    Location
    Colombia
    Posts
    714
    @CJ_London Seems to be the same issue as just mentioned. I'm not working in a continuous form. The db won't run in Office 365 64-bit and I can't even close the database! But looking at the code, I don't see what I'm looking for. Maybe I'm just not looking in the correct place.

  6. #6
    jojowhite's Avatar
    jojowhite is offline Competent Performer
    Windows 11 Access 2021
    Join Date
    Jan 2025
    Posts
    434
    here is the demo db again, open the single form, TestsingleForm and
    play with the combobox and buttons.
    see the VBA behind the form.
    Attached Files Attached Files

  7. #7
    twgonder is offline Expert
    Windows 10 Access 2021
    Join Date
    Jun 2022
    Location
    Colombia
    Posts
    714
    @jojowhite I looked the new db over, I don't see the answer to this from the OP:
    "...in the third one I'm trying to precisely position the scroll bar much finer than by a "line"".

    Am I missing something?


  8. #8
    jojowhite's Avatar
    jojowhite is offline Competent Performer
    Windows 11 Access 2021
    Join Date
    Jan 2025
    Posts
    434
    that is as far as i can go, maybe someone has the right answer for you.
    goodluck with your project.

  9. #9
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,932
    @twonger - perhaps provide an example of what you mean.

  10. #10
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,556
    I looked at the Lebans idea, some said it doesn't work in newer versions of Access. With Office 365 I can't open the .mdb file to peek.
    Here is the DB as an Access 2007 accdb.
    Attached Files Attached Files
    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

  11. #11
    twgonder is offline Expert
    Windows 10 Access 2021
    Join Date
    Jun 2022
    Location
    Colombia
    Posts
    714
    Quote Originally Posted by CJ_London View Post
    @twonger - perhaps provide an example of what you mean.
    I think the original post did that, but let's just say I want to scroll down 4cm.

  12. #12
    twgonder is offline Expert
    Windows 10 Access 2021
    Join Date
    Jun 2022
    Location
    Colombia
    Posts
    714
    @Welsjgasman

    I've looked at two, one on the page of Lebans and one from CJ_London, neither work in Office 365 64 bit.

  13. #13
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,556
    Quote Originally Posted by twgonder View Post
    @Welsjgasman

    I've looked at two, one on the page of Lebans and one from CJ_London, neither work in Office 365 64 bit.
    Up to you to alter for 64bit.
    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

  14. #14
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,932
    I think the original post did that, but let's just say I want to scroll down 4cm.
    If it was clear, I wouldn't have asked, and your original post said you want to scroll less than a line, now you want 4cm.

    Using the scrollbar you can scroll less than a line, but using the mousewheel will scroll a line (if I understand what you mean by a line)

    Since the examples provided don't work for you, I recommend you google set/get scrollinfo to understand all the parameters involved around scrolling and return data using getscrollinfo to see how it changes. You can also try copilot and chatGPT or other AI. They don't often get it right first time, but will give you a clue where to look, correct terminology etc and help you refine your question.

  15. #15
    twgonder is offline Expert
    Windows 10 Access 2021
    Join Date
    Jun 2022
    Location
    Colombia
    Posts
    714

    Post Been there

    Quote Originally Posted by CJ_London View Post
    ... want to scroll less than a line, now you want 4cm.

    Using the scrollbar you can scroll less than a line, but using the mousewheel will scroll a line (if I understand what you mean by a line)

    ...also try copilot and chatGPT or other AI. They don't often get it right first time, but will give you a clue where to look, correct terminology etc and help you refine your question.
    It was a question, general in nature, as I will want to scroll WITH VBA where I want in several sections of several forms. I SAID scrolling a line works, but finer than that doesn't based on examples I've found in other posts. A LINE is something Microsoft has defined in their API, and in my testing it equals one click of the mouse wheel (and it moves too far for the precision I need). Apparently, Access doesn't use the standard APIs for some things in scrollbars. You wanted an example; I gave you one of possible hundreds that could be less or more than a line.

    I spent two days trying to coax an answer out of ChatGPT. It just kept going around in circles, since it really doesn't have intelligence, it can't find a solution to something no one else has been able to do apparently. And it may not be possible. It just seems odd that the first two lines in my OP code work, but the third won't. I was guessing the syntax may be wrong, or that more is needed to be setup so that one could scroll a specified number of twips instead of a "line".

    Not CJs comment, but I've plowed through the Lebans code, and it seems focused on continuous forms, not what I'm trying to do. Since it won't run in Office 365, I can't and won't be bothered updating it. I don't see anything in there that scrolls as I've asked in the OP.

Page 1 of 3 123 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 5
    Last Post: 09-23-2024, 12:54 PM
  2. Replies: 3
    Last Post: 12-11-2014, 11:26 AM
  3. Replies: 5
    Last Post: 11-06-2013, 02:49 PM
  4. Move query data to a new table using VBA
    By Bob Blooms in forum Programming
    Replies: 1
    Last Post: 09-23-2012, 08:33 PM
  5. VBA Sub Form Move to Last Blank Field
    By TinaCa in forum Programming
    Replies: 3
    Last Post: 08-08-2012, 01:53 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