New Excel Forum

This forum has been moved to TeachExcel.com

Ask all future questions in the New Excel Forum.

ExcelKey

Detect Changes to Textbox

Macros, VBA, Excel Automation, etc.

Detect Changes to Textbox

Postby The_JoeBob » Tue Jan 26, 2016 3:04 pm

Good afternoon,

Let me start by saying that I am very new to the world of VBA.

That said...I have a command button "cmdHomeSave" that saves all textbox/combo box data to an excel worksheet. when that button is clicked, a label pops up on the bottom of the userform that says "Form Saved". What I am trying to figure out....and am failing miserably at is....if I make a change to any one of the textboxes or combo boxes, I would like the label to go away, essentially prompting the user to save the data once the changes have been made. How do I do this without duing a sub for each textbox/combobox_Change()?
  • 0

The_JoeBob
Rookie
 
Posts: 3
Joined: Jan 26, 2016
Reputation: 0
Excel Version: 2013

Re: Detect Changes to Textbox

Postby NoSparks » Tue Jan 26, 2016 3:54 pm

I would like the label to go away, essentially prompting the user to save the data once the changes have been made.
I don't follow this at all as it was the save that displayed the label.

If you can post a sample workbook (sanitized, of course) with the user form, I'd be more than happy to take a look.
  • 0

NoSparks
Excel Hobbyist
 
Posts: 637
Joined: May 28, 2014
Reputation: 103
Excel Version: 2010

Re: Detect Changes to Textbox

Postby The_JoeBob » Wed Jan 27, 2016 7:18 am

NoSparks, thanks for responding...

Essentially when the individual fills out all the text and combo boxes and saves the userform, the data dumps into the workbook and a label pops up that says "Form Saved"... the code for it is very basic. I did this to show the user that the information they input was indeed saved.
Code: Select all
Private Sub cmdHome_Click()
lblHomeSaved.Visible = True
ws.range("B3") = txtLastName.Value
ws.Range("B4") = txtFirstName.Value
End Sub


The problem I run into is in the scenario where the user has to go back and make a change to any of the text or combo boxes after the form has been saved. If they do make a change, I would like the "lblHomeSaved" to not be visible anymore since changes were made to the original form and they would have to save the form again. The only way I know how to do that is by going into each text and combo box and writing the following code...

Code: Select all
Private Sub txtLastName_Change()
lblHomeSaved.Visible = False
End Sub

Private Sub cboCOC_Change()
lblHomeSaved.Visible = False
End Sub


I have a lot of text and combo boxes on this form and was wondering if there was a way to get this done faster.
  • 0

The_JoeBob
Rookie
 
Posts: 3
Joined: Jan 26, 2016
Reputation: 0
Excel Version: 2013

Re: Detect Changes to Textbox

Postby NoSparks » Wed Jan 27, 2016 1:53 pm

How to have the same code run from multiple text boxes, without individually programming the text boxes, is a question asked often throughout all the Excel forums. There doesn't seem to be any one-size fits all answer but the suggested solutions invariably require some kind of class module, something I've never needed to deal with (yet).

Had you attached a file with your user form, I'd have experimented with something along the lines of what Rory describes as a simple example in response to a question over at stackoverflow.
  • 0

NoSparks
Excel Hobbyist
 
Posts: 637
Joined: May 28, 2014
Reputation: 103
Excel Version: 2010

Re: Detect Changes to Textbox

Postby The_JoeBob » Wed Jan 27, 2016 3:53 pm

No worries...Thanks for your help!!
  • 0

The_JoeBob
Rookie
 
Posts: 3
Joined: Jan 26, 2016
Reputation: 0
Excel Version: 2013


Return to Macros and VBA Questions

Who is online

Users browsing this forum: No registered users and 148 guests