Error on forms

Juliame9

New Member
Joined
Jan 10, 2018
Messages
12
Hi guys,

I have a userform and sometimes if you don't input a value in one of the textboxes, you get and error.
I want that when there's an error, a messagebox will disply "Please fill in the missing fields" and then go back to the form for the client to continue using it.

I tried:
On Error GoTo ErrMsg
ErrMsg:
MsgBox ("Please fill in the missing fields"), , "Error"
Resume Next

but it just makes the messagebox pop multiple times and you need to press ok several times until it closes.

Any ideas how I can solve this?

Thanks!
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Can you post the code where the error occurs?
 
Upvote 0
Can you post the code where the error occurs?

What do you mean "post the code where the error occurs"?
Basically it happens when the user doesn't put a value that needed for a calculation in a textbox. So I have a button "Calculate" that runs calculations on several textboxes in the form, but if the user missed any textbox, then there's an error because the code can't run when it has not values.

Hope this is what you meant...
 
Upvote 0
Isn't there a line of code highlighted when you get the error and click Debug?
 
Upvote 0
Why not just add Exit Sub to the code you posted earlier?

That would return you do the form.
 
Upvote 0
Because it does return me to the form, but then even if I fill in the missing fields, I still get the error message (in this case the messagebox I defined)
 
Upvote 0
Sorry but without seeing the rest of the code I can't really help any further.
 
Upvote 0
this is the entire code:

Code:
Private Sub CmdCalc_Click()
If InStr(TxtCapital, "%") > 0 Then
    TxtCapital = Replace(TxtCapital, "%", "")
End If
Payoff = Application.WorksheetFunction.Pmt(TxtCapital / 1200, TxtAmort, -TxtHW) + TxtService
ClickCost = CDbl(TxtIMP.Value) * CDbl(TxtClick.Value) * 10000
If TxtColors <> "" Then
Fixed.Visible = True
Variable.Visible = True
Label21.Visible = True
Label26.Visible = True
Label35.Visible = True
Total2.Visible = True
Fixed = CDbl(TxtLabor.Text) + Payoff
Variable = CDbl(TxtSubs.Text) * CDbl(TxtIMP.Text) * 10000 / CDbl(TxtColors.Text) + CDbl(ClickCost.Text)
Total2 = CDbl(Fixed.Text) + CDbl(Variable.Text)
End If
If TxtMargin <> "" Then
Label42.Visible = True
Label44.Visible = True
Margin.Visible = True
Revenue.Visible = True
Revenue = CDbl(Total2.Text) * (1 + CDbl(TxtMargin.Text) / 100)
Margin = Total2 * (1 + TxtMargin / 100) - Total2
End If
Total1 = CDbl(Payoff.Text) + CDbl(ClickCost.Text)
If TxtEPMClick <> "" Then
Label27.Visible = True
Label28.Visible = True
Label39.Visible = True
Label40.Visible = True
EPMClickCost.Visible = True
EPMVariable.Visible = True
TotalEPM1.Visible = True
TotalEPM2.Visible = True
Label57.Visible = True
EPMMargin.Visible = True
End If
If TxtColors > 3 And TxtEPMClick <> "" Then
EPMClickCost = CDbl(TxtIMP.Value) * 1000000 * (CDbl(TxtColors.Text) - 1) / CDbl(TxtColors.Text) * TxtEPMClick / 100
EPMVariable = CDbl(EPMClickCost.Value) + CDbl(TxtSubs.Text) * CDbl(TxtIMP.Value) * 10000 / CDbl(TxtColors.Value)
TotalEPM1 = CDbl(Payoff.Text) + CDbl(EPMClickCost.Text)
TotalEPM2 = CDbl(Fixed.Text) + CDbl(EPMVariable.Text)
EPMMargin = Total2 * (1 + TxtMargin / 100) - TotalEPM2
End If
If InStr(TxtMargin, "%") > 0 Then
    TxtMargin = Replace(TxtMargin, "%", "")
End If
End Sub
 
Last edited by a moderator:
Upvote 0

Forum statistics

Threads
1,215,326
Messages
6,124,267
Members
449,149
Latest member
mwdbActuary

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top