Set Boolean Variable for Changing Any Control on Userform

R

Ryan H

I want to notify the user if they make any changes to the userform when they
click the OK button on the userform. The userform has about 90 controls on
it. Do I have to set the variable bolFormChanged = True under a Change Event
for each control or is there a shortcut to doing this?

Thanks in Advance!

For Example,

Private Sub btnOK_Click()

If bolFormChanged = True Then
' notify user with msgbox
Else
' Do This
End If

End Sub
 
J

Jacob Skaria

Use the tag property to store the values on click OK and check that everytime
when you click OK . Something as below

Private Sub btnOK_Click()

'Click OK
Dim blnChange As Boolean
For Each ctl In UserForm1.Controls
If ctl.Tag <> ctl.Text Then blnChange = True
ctl.Tag = ctl.Text
Next

If blnChange = True Then
'Data changed
'do something
End If


End Sub
 
J

Jacob Skaria

Hi Ryan

Code slightly modified to filter controls...by type..the below will look for
changes in Textbox controls and combox controls. Adjust to suit...

Private Sub btnOK_Click()

'Click OK
Dim blnChange As Boolean
For Each ctl In UserForm1.Controls
If TypeName(ctl) = "TextBox" Or TypeName(ctl) = "ComboBox" Then
If ctl.Tag <> ctl.Text Then blnChange = True
ctl.Tag = ctl.Text
End If
Next

If blnChange = True Then
'Data changed do something
End If


End Sub



If this post helps click Yes
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top