![]() |
Excel UserForm textboxes and checkboxes???
I have a Userform with textboxes and checkboxes. I want to add a "Cancel"
command button that when clicked on button it will ask if you want to cancel the form. If yes, clear all textboxes and checkboxes. If no, leave as it and continue. How do I write this code? Any help will be greatly appreciated. Thank you. |
Excel UserForm textboxes and checkboxes???
This should do what you need: Code: -------------------- Private Sub CommandButton1_Click() Dim cCont As Control If MsgBox("Do you really want to cancel?", vbYesNo, "Cancel Action") = vbYes Then For Each cCont In Me.Controls If TypeName(cCont) = "CheckBox" Then cCont.Value = False End If If TypeName(cCont) = "TextBox" Then cCont.Value = "" End If Next cCont End If End Sub -------------------- TotallyConfused;488536 Wrote: I have a Userform with textboxes and checkboxes. I want to add a "Cancel" command button that when clicked on button it will ask if you want to cancel the form. If yes, clear all textboxes and checkboxes. If no, leave as it and continue. How do I write this code? Any help will be greatly appreciated. Thank you. -- Simon Lloyd Regards, Simon Lloyd 'Microsoft Office Help' (http://www.thecodecage.com) ------------------------------------------------------------------------ Simon Lloyd's Profile: http://www.thecodecage.com/forumz/member.php?userid=1 View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=134692 |
Excel UserForm textboxes and checkboxes???
Thank you for responding. However, realized that I want to keep only one
text box from clearing? It is a Date textbox. Me.txtFormDate = Date 'Me.FormDate = format(date,"mm-dd-yyyy"). Is this possible to clear everything else but this one textbox? Thank you. "Simon Lloyd" wrote: This should do what you need: Code: -------------------- Private Sub CommandButton1_Click() Dim cCont As Control If MsgBox("Do you really want to cancel?", vbYesNo, "Cancel Action") = vbYes Then For Each cCont In Me.Controls If TypeName(cCont) = "CheckBox" Then cCont.Value = False End If If TypeName(cCont) = "TextBox" Then cCont.Value = "" End If Next cCont End If End Sub -------------------- TotallyConfused;488536 Wrote: I have a Userform with textboxes and checkboxes. I want to add a "Cancel" command button that when clicked on button it will ask if you want to cancel the form. If yes, clear all textboxes and checkboxes. If no, leave as it and continue. How do I write this code? Any help will be greatly appreciated. Thank you. -- Simon Lloyd Regards, Simon Lloyd 'Microsoft Office Help' (http://www.thecodecage.com) ------------------------------------------------------------------------ Simon Lloyd's Profile: http://www.thecodecage.com/forumz/member.php?userid=1 View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=134692 |
Excel UserForm textboxes and checkboxes???
Since you need to reset the date in this text box. Add the below line after
the code Simon has given. Me.FormDate = format(date,"mm-dd-yyyy") If this post helps click Yes --------------- Jacob Skaria "TotallyConfused" wrote: Thank you for responding. However, realized that I want to keep only one text box from clearing? It is a Date textbox. Me.txtFormDate = Date 'Me.FormDate = format(date,"mm-dd-yyyy"). Is this possible to clear everything else but this one textbox? Thank you. "Simon Lloyd" wrote: This should do what you need: Code: -------------------- Private Sub CommandButton1_Click() Dim cCont As Control If MsgBox("Do you really want to cancel?", vbYesNo, "Cancel Action") = vbYes Then For Each cCont In Me.Controls If TypeName(cCont) = "CheckBox" Then cCont.Value = False End If If TypeName(cCont) = "TextBox" Then cCont.Value = "" End If Next cCont End If End Sub -------------------- TotallyConfused;488536 Wrote: I have a Userform with textboxes and checkboxes. I want to add a "Cancel" command button that when clicked on button it will ask if you want to cancel the form. If yes, clear all textboxes and checkboxes. If no, leave as it and continue. How do I write this code? Any help will be greatly appreciated. Thank you. -- Simon Lloyd Regards, Simon Lloyd 'Microsoft Office Help' (http://www.thecodecage.com) ------------------------------------------------------------------------ Simon Lloyd's Profile: http://www.thecodecage.com/forumz/member.php?userid=1 View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=134692 |
Excel UserForm textboxes and checkboxes???
Thank you very much. So easy, I was close but was making it complicated.
Thanks again very much appreciated. "Jacob Skaria" wrote: Since you need to reset the date in this text box. Add the below line after the code Simon has given. Me.FormDate = format(date,"mm-dd-yyyy") If this post helps click Yes --------------- Jacob Skaria "TotallyConfused" wrote: Thank you for responding. However, realized that I want to keep only one text box from clearing? It is a Date textbox. Me.txtFormDate = Date 'Me.FormDate = format(date,"mm-dd-yyyy"). Is this possible to clear everything else but this one textbox? Thank you. "Simon Lloyd" wrote: This should do what you need: Code: -------------------- Private Sub CommandButton1_Click() Dim cCont As Control If MsgBox("Do you really want to cancel?", vbYesNo, "Cancel Action") = vbYes Then For Each cCont In Me.Controls If TypeName(cCont) = "CheckBox" Then cCont.Value = False End If If TypeName(cCont) = "TextBox" Then cCont.Value = "" End If Next cCont End If End Sub -------------------- TotallyConfused;488536 Wrote: I have a Userform with textboxes and checkboxes. I want to add a "Cancel" command button that when clicked on button it will ask if you want to cancel the form. If yes, clear all textboxes and checkboxes. If no, leave as it and continue. How do I write this code? Any help will be greatly appreciated. Thank you. -- Simon Lloyd Regards, Simon Lloyd 'Microsoft Office Help' (http://www.thecodecage.com) ------------------------------------------------------------------------ Simon Lloyd's Profile: http://www.thecodecage.com/forumz/member.php?userid=1 View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=134692 |
All times are GMT +1. The time now is 06:25 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com