H
Hennie Neuhoff
Hi. Guys
What I would like to do:
Get the user to select a product from a list [listbox1-"VrdLys" ; Userform
UcalCost]
Once his made the selection - promp to supply the quantity in a textbox
[TxtQuantity]
Calculate the cost - which is equal to the amount entered in txtQuantity
* the corresponding price of the product selected in Listbox1
Prompt the user to confirm his selection.
What I've achieved:
The list slection with the corresponding price of each product.
The calulation displayed in TboxAntw works 100%
My problem!
The prompt to supply the quantity does not work the way I want it. Only
after I've entered a number in TxtQuantity does the Inputbox appear to get
the quantity from the user - the result is corectly displayed in TxtQuantity.
I have a command button (CmnCost) when clicked it does the calculation
which is corectly displayed in TboxAntw. I would like this calculation to
be "automated" - if the user supply the quantity - the calculation should
automatically be displayed in TboxAntw without using the command button.
Finally I’m not sure how to get the user to confirm his selection on the
userform.
Tks in advance
This is my code:
Public Sub CalCost()
Dim N, TxtQuantity
'Get the product, quantity & calculate the cost
UCalCost.ListBox1.Clear
'select the item
UCalCost.ListBox1.RowSource = "VrdLys"
UCalCost.ListBox1.ListIndex = 0
UCalCost.TxtQuantity = ""
UCalCost.TboxAntw.Value = 0
UCalCost.Show
'get the number of the item selected in the box
N = UCalCost.ListBox1.ListIndex
With UCalCost.ListBox1
'Display selection & calc - sheet AanInlig
Worksheets("AanInlig").Range("tydvrd").Value = UCalCost.ListBox1.Value
Worksheets("AanInlig").Range("tydaan").Value = UCalCost.TxtQuantity.Value
Worksheets("AanInlig").Range("tydkos").Value = UCalCost.TboxAntw.Value
End With
Unload UCalCost
End Sub
This is the Userform code:
Private Sub CmnCost_Click()
If Me.TxtQuantity.Value <> "" Then
prod = Me.ListBox1.Value
Pprice = Application.WorksheetFunction.Index(Range("VrdVerPry") _
, Application.WorksheetFunction.Match(prod, Range("VrdLys"), 0))
TboxAntw = Pprice * TxtQuantity
End If
End Sub
Private Sub ListBox1_Click()
End Sub
Private Sub OkButton_Click()
ULysKoste.Hide
bContinue = True
End Sub
Private Sub TxtQuantity_Change()
TxtQuantity = Application.InputBox(prompt:="Quantity ?")
End Sub
What I would like to do:
Get the user to select a product from a list [listbox1-"VrdLys" ; Userform
UcalCost]
Once his made the selection - promp to supply the quantity in a textbox
[TxtQuantity]
Calculate the cost - which is equal to the amount entered in txtQuantity
* the corresponding price of the product selected in Listbox1
Prompt the user to confirm his selection.
What I've achieved:
The list slection with the corresponding price of each product.
The calulation displayed in TboxAntw works 100%
My problem!
The prompt to supply the quantity does not work the way I want it. Only
after I've entered a number in TxtQuantity does the Inputbox appear to get
the quantity from the user - the result is corectly displayed in TxtQuantity.
I have a command button (CmnCost) when clicked it does the calculation
which is corectly displayed in TboxAntw. I would like this calculation to
be "automated" - if the user supply the quantity - the calculation should
automatically be displayed in TboxAntw without using the command button.
Finally I’m not sure how to get the user to confirm his selection on the
userform.
Tks in advance
This is my code:
Public Sub CalCost()
Dim N, TxtQuantity
'Get the product, quantity & calculate the cost
UCalCost.ListBox1.Clear
'select the item
UCalCost.ListBox1.RowSource = "VrdLys"
UCalCost.ListBox1.ListIndex = 0
UCalCost.TxtQuantity = ""
UCalCost.TboxAntw.Value = 0
UCalCost.Show
'get the number of the item selected in the box
N = UCalCost.ListBox1.ListIndex
With UCalCost.ListBox1
'Display selection & calc - sheet AanInlig
Worksheets("AanInlig").Range("tydvrd").Value = UCalCost.ListBox1.Value
Worksheets("AanInlig").Range("tydaan").Value = UCalCost.TxtQuantity.Value
Worksheets("AanInlig").Range("tydkos").Value = UCalCost.TboxAntw.Value
End With
Unload UCalCost
End Sub
This is the Userform code:
Private Sub CmnCost_Click()
If Me.TxtQuantity.Value <> "" Then
prod = Me.ListBox1.Value
Pprice = Application.WorksheetFunction.Index(Range("VrdVerPry") _
, Application.WorksheetFunction.Match(prod, Range("VrdLys"), 0))
TboxAntw = Pprice * TxtQuantity
End If
End Sub
Private Sub ListBox1_Click()
End Sub
Private Sub OkButton_Click()
ULysKoste.Hide
bContinue = True
End Sub
Private Sub TxtQuantity_Change()
TxtQuantity = Application.InputBox(prompt:="Quantity ?")
End Sub