PDA

View Full Version : [SOLVED:] I want my reset button on VBA userform to do nothing if "no" is selected



Ryanchris
10-24-2019, 09:21 PM
Newby here...again!

I have a reset button (actually named "New System") that gets pushed AFTER the "Upload" button is hit and is designed to clear my userform. The issues I am having is using the vbYes/No in my MsgBox. If "New System" button is pushed, and user confirms "yes" - I want the sheet to clear. If they select "no", I want the sheet to just stay exactly as it is. I feel like this should be easy but what the hell am I missing??!!

Here is my current code:

Private Sub CommandButton17_Click()


MsgBox "Do not forget to UPLOAD your configuration. Are you sure you want to continue?", vbYesNo, "New Config"


If vbYes Then


Dim ctl As Control


For Each ctl In CondensingUnitConfig.Controls
If TypeName(ctl) = "TextBox" Then
ctl.Value = ""
End If

Next ctl
For Each ctl In CondensingUnitConfig.Controls
If TypeName(ctl) = "ComboBox" Then
ctl.Value = ""
End If

Next ctl


End If


End Sub

大灰狼1976
10-24-2019, 09:36 PM
Hi Ryanchris!
Little change like below:

n = MsgBox("Do not forget to UPLOAD your configuration. Are you sure you want to continue?", vbYesNo, "New Config")
If n = vbYes Then
...


--Okami

Ryanchris
10-24-2019, 09:43 PM
Thank you Okami! That worked. I'm not sure why but glad that it does! Really appreciate you and this forum!

大灰狼1976
10-24-2019, 09:54 PM
Explain a little:
"vbYes" is a constant,"If vbYes Then" is equivalent to "If vbYes = True Then", This judgment has nothing to do with your choice. It's always true.

--Okami

Ryanchris
10-24-2019, 10:02 PM
That makes sense. OK! Thank you!