M
M
m_shpakov2016-04-05 17:27:50
Visual Basic
m_shpakov, 2016-04-05 17:27:50

VBA form crashes with object required, what's the problem?

In general, I already wrote in different ways, I even tried to simply change the text in the label - the same mistake. Went through the code in pieces - it always crashes.
The essence is this: create a custom form for calculating the change for the purchase of goods with the fields: Price, Quantity, Amount, Paid, Change.
Here is the code:

Private Sub chek_Click()

Dim sum As Single
Dim cost As Single
Dim quantity As Single
Dim made As Single
Dim total As String

cost = Val(UserForm.cost.Text)
quantity = Val(UserForm.quantity.Text)
made = Val(UserForm.made.Text)

sum = cost * quantity
total = CStr(made - sum)

UserForm.Label6.Text = total

End Sub

I can give you a file. Already tried to count in one line - still an error.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Fedoryan, 2016-04-05
@m_shpakov

Slightly changed the code, here is the file
Most likely, as mentioned above, the controls on the form or the form itself are incorrectly named

Private Sub Check_Click()
    Dim cost, quantity, summ, made, total As Double
    
    cost = Val(UserForm1.tCost.Text)
    quantity = Val(UserForm1.tQuantity.Text)
    made = Val(UserForm1.tMade.Text)
    
    summ = cost * quantity
    UserForm1.lSum.Caption = Str(summ)
    
    total = made - summ
    UserForm1.lTotal.Caption = Str(total)
End Sub

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question