Reputation: 113
I have a userform that can be filled in but only if a previous userform was filled in as there are calculations in the userform based on the previous input and if those are empty, the calculations crash.
Now I did write a few if statements that check for these empty values and then had a brain flash.. how about if one of the fields is missing, the userform is just disabled. So thought, so done and it works :)
if DP1 = "" then
reportback.enable = false
else
end if
That is the form and it shows up beautifully and nothing can be changed, but Ohhh.. you can´t even close the form, nothing works .. lol.
So my question. Is there a way to disable all fields from any input but still have the cancel button active ?
Private Sub Cancel_Click()
Unload reportback
End Sub
Upvotes: 2
Views: 7540
Reputation: 12353
Use below code to disable all controls on your form to avoid the issue. UserForm1 refers to name of Userform kindly replace accordingly.
Dim ctrl As Control
For Each ctrl In UserForm1.Controls
ctrl.Enabled = False
Next
Set ctrl = Nothing
Upvotes: 5