+ Reply to Thread
Results 1 to 21 of 21

Adding a value textbox to a userform

  1. #1
    Forum Contributor
    Join Date
    04-22-2015
    Location
    Scotland
    MS-Off Ver
    365
    Posts
    171

    Adding a value textbox to a userform

    Hi Forum
    Wonder if anyone could help me adding a textbox to a userform that will show the highest current number in Row A,
    I can add the textbox ok and can create a formula to show the highest number but not getting anything to show on the userform textbox. The Private Sub I created is as below so looking for a formula that will make it pick up the amount sitting in Row AM1 of worksheet2

    Please Login or Register  to view this content.
    Thanks for any help you can provide.
    J

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Adding a value textbox to a userform

    You could use the userform Initialize event to populate the textbox, and if you only want to display the max value you should probably consider using a label rather than a textbox.
    If posting code please use code tags, see here.

  3. #3
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,014

    Re: Adding a value textbox to a userform

    .
    Please Login or Register  to view this content.


    Late edit: sorry Norie ... I was posting after you.

  4. #4
    Forum Contributor
    Join Date
    04-22-2015
    Location
    Scotland
    MS-Off Ver
    365
    Posts
    171

    Re: Adding a value textbox to a userform

    Hi Norie and Logit
    Thanks a lot for both your inputs, I tried loading the code below into UserForm Initialize but it created an error "Compile Error: Ambiguous name detected: UserForm_Initialize" Am I missing something obvious?

    Please Login or Register  to view this content.
    Cheers

  5. #5
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,014

    Re: Adding a value textbox to a userform

    .
    "UserForm" should be named "UserForm1" if you did not name it something else and you only have one userform.

  6. #6
    Forum Contributor
    Join Date
    04-22-2015
    Location
    Scotland
    MS-Off Ver
    365
    Posts
    171

    Re: Adding a value textbox to a userform

    Hi, I only have one UserForm which is called UserForm1, although I already use Initialize in the code below to load a Combo "LoadComboBox". Would that prevent me running another? Thanks

    Please Login or Register  to view this content.

  7. #7
    Forum Expert torachan's Avatar
    Join Date
    12-27-2012
    Location
    market harborough, england
    MS-Off Ver
    Excel 2010
    Posts
    4,304

    Re: Adding a value textbox to a userform

    You can only have one initialise event per userform.
    the third row in code below reads the cell AM1 in sheet2
    see demo file

    Please Login or Register  to view this content.
    Attached Files Attached Files

  8. #8
    Forum Contributor
    Join Date
    04-22-2015
    Location
    Scotland
    MS-Off Ver
    365
    Posts
    171

    Re: Adding a value textbox to a userform

    Hi Torachan
    Demo does exactly as I need it to but if I cant use UserForm1 how do I get it on the same userform?
    Thought I would add a sample copy of the userform im working with to hopefully explain better.
    On top left corner is Next Ref No. which I need to pick up from cell AM1, formula in this cell is =MAX(A:A)+1
    to add one to show next available no. I you can think of anything that would be great.

    Another thing I am trying to change is the date format on rows C,D and N which are mm/dd/yyyy where I need dd/mm/yyyy if you
    know where this can be changed. I changed it in the worksheet but userform is not changing.

    Thanks
    J
    Attached Files Attached Files

  9. #9
    Forum Expert torachan's Avatar
    Join Date
    12-27-2012
    Location
    market harborough, england
    MS-Off Ver
    Excel 2010
    Posts
    4,304

    Re: Adding a value textbox to a userform

    Rather than search for new max number on initialisation I have put the code on a new button.
    The reason for this is that on add new client the form clears including new number-with the seperate button it can be recalled at any time - there are no formula on the sheet now.
    Also add DateValue to 3 items in the combobox search code.
    No matter what you name your userform the UserForm initialization is always named just UserForm and will not be recognised as anything else.
    Attached Files Attached Files

  10. #10
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,014

    Re: Adding a value textbox to a userform

    .
    The loading (initializing) of the UserForm should suffice for updating the value of TextBox1 ... but ... this is confusing because
    what should work ... isn't.

    I was able to have the value from AM1 populate TextBox1 with the following edit of the code :

    Please Login or Register  to view this content.
    However, the above is not standard coding from my experience.

    Comments ?

  11. #11
    Forum Expert torachan's Avatar
    Join Date
    12-27-2012
    Location
    market harborough, england
    MS-Off Ver
    Excel 2010
    Posts
    4,304

    Re: Adding a value textbox to a userform

    @Logit, indeed it would and does, however the ClearForm sub immediately clears the textbox. hence your textbox1_change event then refilled the text box
    If the line TextBox1=cells(1,39) had been put after the ClearForm event there then would be no need for the TextBox1_Change event.
    Also I was trying to emphasize that the initialization does not use the form name - along with activate they are two process that are automatically given priority on opening a userform.
    The reason I committed it to code and a button is personal preference - I hate dribs and drabs of formula in a sheet when using VBA.
    torachan

  12. #12
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,014

    Re: Adding a value textbox to a userform

    .
    I overlooked the ClearForm call. My oops !

    Please Login or Register  to view this content.
    Interesting how the mind can focus on a single thing and miss the obvious. Duh !

  13. #13
    Forum Contributor
    Join Date
    04-22-2015
    Location
    Scotland
    MS-Off Ver
    365
    Posts
    171

    Re: Adding a value textbox to a userform

    Torachan that works perfectly as does the dating , many thanks.

    Logit, Norie I really appreciate you both also looking at the for me, again thank you.

  14. #14
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,014

    Re: Adding a value textbox to a userform

    .
    Glad to help ...

    You are welcome.

  15. #15
    Forum Contributor
    Join Date
    04-22-2015
    Location
    Scotland
    MS-Off Ver
    365
    Posts
    171

    Re: Adding a value textbox to a userform

    Hi Torachan
    I know said the tool works perfectly (as it does for current data) but when I load new data it shows an error Run Time Error '13': Type mismatch when i look at the ComboBox1_Change it highlights the datavalues below. Would you have any idea what I can change to allow new records to be entered? Thank you.

    Please Login or Register  to view this content.

  16. #16
    Forum Expert torachan's Avatar
    Join Date
    12-27-2012
    Location
    market harborough, england
    MS-Off Ver
    Excel 2010
    Posts
    4,304

    Re: Adding a value textbox to a userform

    Delete the three rows in your post#15

    paste the code below over the existing 'ADD' sub.
    Please Login or Register  to view this content.
    Format the three date columns as per format in clip.
    Format the complete columns - not just the table content - the format needs to be in place ready to receive added data.

    Attachment 703116

  17. #17
    Forum Contributor
    Join Date
    04-22-2015
    Location
    Scotland
    MS-Off Ver
    365
    Posts
    171

    Re: Adding a value textbox to a userform

    Thanks for the reply Torachan, sorry I didn't get back yesterday, I only got back on my PC today.
    I think I follow what your are saying needs to be done but just before I try it, I can't open the attachment as it tells me to contact administrator, does it just show how I should format the three data columns? i.e. is it just going through Custom and selecting dd/mm/yyyy?

  18. #18
    Forum Expert torachan's Avatar
    Join Date
    12-27-2012
    Location
    market harborough, england
    MS-Off Ver
    Excel 2010
    Posts
    4,304

    Re: Adding a value textbox to a userform

    goto 'Date' and formatCapture.JPG

  19. #19
    Forum Contributor
    Join Date
    04-22-2015
    Location
    Scotland
    MS-Off Ver
    365
    Posts
    171

    Re: Adding a value textbox to a userform

    Tried a few different ways to make the adjustments you suggested Torachan but not having any luck. I know its a lot to ask but is there any chance you could make the suggested changes to the original "Sample Form(tora(v1)).xlsm‎" you sent me and resend? Just not sure I'm going to get it running and its so near what I need.

    Its for a brain damage charity to load client data as their Access tool crashed, managed to pull their data and trying build something simple for them as a replacement.

    Thanks for your help..

  20. #20
    Forum Expert torachan's Avatar
    Join Date
    12-27-2012
    Location
    market harborough, england
    MS-Off Ver
    Excel 2010
    Posts
    4,304

    Re: Adding a value textbox to a userform

    attached file updated and working OK.
    if you are pasting in data - paste values only - not formatting as this is likely to overwrite the date format.
    Attached Files Attached Files

  21. #21
    Forum Contributor
    Join Date
    04-22-2015
    Location
    Scotland
    MS-Off Ver
    365
    Posts
    171

    Re: Adding a value textbox to a userform

    Perfect... Thank you so much for your help with this..

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Userform Listbox updating and adding values using Textbox
    By zubinnajmi in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-16-2019, 12:55 PM
  2. Adding Textbox as cooltiptext in a front of frame on userform
    By jaryszek in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 03-22-2019, 05:21 AM
  3. Creating Shapes and adding UserForm with Textbox [in Loop]
    By JonasBig2 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-10-2018, 11:23 PM
  4. Adding figures in userform textbox formatted as Euro
    By TG58 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-07-2016, 03:37 AM
  5. Adding figures in userform textbox formatted as Euro
    By TG58 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-06-2016, 08:49 AM
  6. Calculating/adding userform textbox values based on combobox selection and display to cell
    By SpreadsheetGirl in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-04-2015, 08:57 AM
  7. adding consecutive number to userform textbox
    By jsmity in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 04-10-2008, 09:04 AM

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