+ Reply to Thread
Results 1 to 9 of 9

Update Userform textboxes on the fly

  1. #1
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Update Userform textboxes on the fly

    I've got a workbook (attached) with a UserForm that summarizes transactions entered in columns A and B based on the entry (color) in column A. If you click on the Button (Summary (Show/Hide)) it brings up the UserForm.

    A couple of issues I've struggled with:
    1. I'd like the UserForm to open when the workbook opens.
    2. I'd like the UserForm to update as entries are made in Columns A and B when the user tabs out of column B
    3. I'd like the UserForm to always stay open; the user cannot close it.

    I've got the same data in cells G26:M34 but these cells don't "float" as the page moves down. This is the reason I've gone to a UserForm to accumulate the data.

    I've spent several days trying various methods but cannot figure it out. Any ideas how I can accomplish this?

    Thanks, John
    Attached Files Attached Files
    Last edited by jaslake; 05-12-2009 at 12:08 PM. Reason: Clarify

  2. #2
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Update Userform textboxes on the fly

    I've solved Issue 1; the UserForm now opens when the workbook opens.

    Still have not resolved Issues 2 and 3.

    Any Ideas?

    John

  3. #3
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Update Userform textboxes on the fly

    You would probably need to unload the userform then re-load it usig the worksheet change event

    Your table seems to show the values, why use the userform. You could set the Control Source of the relevant textbox to the cell in the table
    Last edited by royUK; 05-11-2009 at 01:12 PM.
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  4. #4
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Update Userform textboxes on the fly

    Thanks royUK.

    About an hour ago, I implemented just what you suggessted and it does perform the task I was looking to do. However, it creates another problem. I'll explain below.

    As for the three issues I originally discussed:

    Issue 1 - the UserForm now opens when the workbook is opened.

    Issue 2 - the UserForm now updates "on the fly" (unload/reload)

    Issue 3 - I believe I can prevent the user from closing the UserForm by setting the "Enabled" property to "False". I'm not certain this is the solution yet but it shows promise.

    Now, the new problem I've created for my self in solving Issue 2. When I reload the UserForm, the cursor "appears" to stay with the UserForm and I must left click the mouse to get focus back on column A. I've been researching the WEB for VBA code to send a mouse left click to the applicaton via VBA but have come up with nothing.

    Does my explaination make any sense to you? Do you know of a way around this?

    John

  5. #5
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Update Userform textboxes on the fly

    I forgot to respond to your question. You asked why I'm using a UserForm when I already have a table with the data.

    I originally had the table you referenced at the top of the sheet and I then locked the panes so the table was always in view. But, it simply took up too much room on the screen. And, if I moved it off to the side, it would scroll off the screen as data filled the sheet.

    So, I looked at "floating Textboxes" but could not find anything that looked workable. I decided to try the UserForm approach. I could load it where I wanted it and it would stay there.

    The approach seems to work, except when it doesn't.(smile)

    John

  6. #6
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Update Userform textboxes on the fly

    Here's an example of a FloatingForm

    This will prevent a user closing the form with the red X

    Please Login or Register  to view this content.

  7. #7
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Update Userform textboxes on the fly

    Thanks for that snippet. It works for me. I simply added a "Close" button to the UserForm. Now the User has the option of viewing or not viewing the Summary. Much more friendly.

    All the issues I asked you about have been resolved.

    Issue 1 - Open the UserForm when workbook opens has been resolved with the following code:

    Please Login or Register  to view this content.
    This "seems" to work; I'll need to do more extensive testing.

    Issue 2 - UserForm now updates on the fly. I added this code to the worksheet change event:

    Please Login or Register  to view this content.
    Unload UserForm and UserForm.Show closes the UserForm then reinitializes the UserForm. The last three lines of the code sends a Mouse click to the application and takes the "cursor" focus off the UserForm and puts it back to the worksheet at the selected cell.

    Issue 3 - Not allow the user to close the UserForm was resolved by the snippet you provided.

    Please Login or Register  to view this content.
    Issue 4 - The cursor "appeared" to stay focused on the UserForm after reload. That issue "appears" to have been resolved with this code

    Please Login or Register  to view this content.
    I gotta be honest with you, I have no idea why this fixes the problem or what it's doing.

    I found this code on Mr. Excels Forum (from Gary E)

    Please Login or Register  to view this content.
    and adapted it to my needs.

    Question: In my working career (I'm retired), I did a lot of work in Visual FoxPro. With the software came a manual that was about 1200 pages thick. It contained all the commands, functions and system variables of the language and examples of how and when to use them. Are you aware of something similar thats available for VBA?

    I'll look at the "Floating TextBox" reference you provided. For now, I'm going to mark this thread solved.

    Thanks for your help.

    John

  8. #8
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Update Userform textboxes on the fly

    I don't know of such a manual, the VBA help files or the internet usually suffice.

    AppActivate sets the focus to Excel
    Last edited by royUK; 05-13-2009 at 03:14 AM.

  9. #9
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Update Userform textboxes on the fly

    Well, I found that this code to set focus (simulate a mouse click)

    Please Login or Register  to view this content.
    only works when it sees fit.

    I discovered this code at http://www.ozgrid.com/forum/showthread.php?t=34692 and I believe it's just the ticket.

    Please Login or Register  to view this content.
    In a standard code module

    Please Login or Register  to view this content.
    This code shifts focus from the UserForm to the worksheet. I've been beating up on it all day and I've not been able to break it.

    Thanks again for all your help.

    John

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1