Logo 
Search:

MS Office Forum

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds

How to detect user modification of textboxes on a form?

  Asked By: Mali    Date: Sep 20    Category: MS Office    Views: 1178
  

I have a form with multiple textboxes, and a couple of command
buttons, my question is, is there a way
to detect if the user has entered/altered values in "any" of the
textboxes, without having to go through
the process of comparing each and every textbox with the original
string?

I need to detect any change, to decide if the worksheet needs saving
on moving to the next row of data?

Is there an easy way to do this?, or can the textboxes somehow
indicate if anything has been edited?

Share: 

 

8 Answers Found

 
Answer #1    Answered By: Raymond Fischer     Answered On: Sep 20

I think if you use the keypress, like example below, it will give you
what you want.

Private Sub txtAcctNum_KeyPress(ByVal KeyAscii As
MSForms.ReturnInteger)
If KeyAscii < Asc("0") Or KeyAscii > Asc("9") Then
MsgBox ("Please enter numbers only")
End If
End Sub

Or AfterUpdate might better meet your needs, see below for an
example:

Private Sub txtAcctNum_AfterUpdate()
Dim hold As Integer
If Len(txtAcctNum) > 5 Then
MsgBox ("Account Number can not exceed 5 digits")
End If
End Sub

 
Answer #2    Answered By: Sebastian Anderson     Answered On: Sep 20

AfterUpdate is a good idea. You can also use Change, except for it fires
with every keystroke.
In AfterUpdate you can set a flag and then check it later. You'll need to
have a change  event handler like this for every one of your textboxes. I
don't think there's a form-wide "dirty" flag.
In my apps, most of the time I don't bother comparing  against the original
value, I just record the change event happening and just assume they changed
something, even if they changed it back to the original value. But that's
me.
I've never come across something significantly easier than this.
Dave

 
Answer #3    Answered By: Inez Wood     Answered On: Sep 20

In a recent Word front end app to an Access DB, I just let it go that if
they made any moves in any field on the form, I assumed they made some
change to the data. So I used the change  event and then set a global
variable that the data was change. That adds the word CHANGED! to the
titlebar of the dialog to draw attention so the user  knows they did
something, in case it was a mistake, but then I also asked...before they
bailed on the dlg...whether they wanted to save the changes.

This way I captured the fact that something change, but left it up to the
user to decipher if the change was something they wanted to commit to the
DB. If they clicked yes on the Q msg...it would pass the data. Otherwise it
would just continue on without saving.

 
Answer #4    Answered By: Natasha Rivera     Answered On: Sep 20

Actually I'm not interested with the first question  which is about TextBox
Change or etc. But what Dave suggested as a solution is in my focus. I mean,
making records in Access DB. But i'm new in this. Please give me some simple
codes about this. And maybe some links.

 
Answer #5    Answered By: Saila Iqbal     Answered On: Sep 20

Just thinking out loud really... isn't there an IsDirty property
somewhere?

 
Answer #6    Answered By: Wallace Kelly     Answered On: Sep 20

I'm pretty new at this, but I do Call several sub routines any time a user
changes a cell value. I have the following code on the worksheet  (right click on
the tab name & select "View Code")

Private Sub Worksheet_Change(ByVal Target As Range)
Call Macro1
Call Macro2
End Sub

This does not fire on each keystroke, but does fire if the user  changes any a
value in any of the unlocked cells and then activates the change  by hitting
<Enter> or moving  to another cell (arrow keys, <Tab>, or mouse click).

 
Answer #7    Answered By: Zack Thompson     Answered On: Sep 20

I think there is a misunderstanding here.
Your code is fine, but it checks the cells.
The initial question  was:
"my question is, is there a way to detect  if the user  has entered/altered
values in "any" of the textboxes"

Let's say that the cells "belong" to the worksheet. So if you want to find out
change  in the worksheet(cells), that's fine (i.e. you check the event that
belongs to the worksheet  list of events)
versus textboxes  which are controls on a userform.
In this case, you need to check other events such as David suggested (i.e.
events that belongs to the textbox  list of events).
I hope I have made it clear.

 
Answer #8    Answered By: Krista Warren     Answered On: Sep 20

You are absolutely correct that I misunderstood the original question  :(

I appreciate you taking the time to offer such a complete explanation... My
whole purpose for monitoring this board is because of excellent and genuine
helpfulness of participants such as yourself.

 
Didn't find what you were looking for? Find more on How to detect user modification of textboxes on a form? Or get search suggestion and latest updates.




Tagged: