newbie to vba im having trouble with listboxs and populating them with the info i need in the correct format.
So i already have 1 listbox (lstResults) which the information in it is taken from a selected item from a combobox (cboxType)
from lstResults i click an item and them in a separate textbox i want to add an amount eg 10 then with a commandbutton add the lstResults information and textbox amount to another listbox in different columns in the same row and then be able to add more with more selections.
ive nearly got it working but it just over writes the last entry.
Code
Private Sub cmdAddItem_Click()
If txtamount.Value = "" Then
MsgBox "Please enter a value"
Exit Sub
Else
' Code if not empty
End If
With Me.ListBox1
.AddItem Me.lstResults.Value
.AddItem Me.txtamount.Value
End With
End Sub
Private Sub cmdClose_Click()
Unload Me
End Sub
Private Sub cboxType_Click()
Dim X As Integer
X = cboxType.ListIndex
Select Case X
Case Is = 0
lstResults.RowSource = "Hinge"
Case Is = 1
lstResults.RowSource = "FlushBolt"
Case Is = 2
lstResults.RowSource = "Lock"
Case Is = 3
lstResults.RowSource = "IntumescentJacket"
Case Is = 4
lstResults.RowSource = "Escutcheon"
Case Is = 5
lstResults.RowSource = "Cylinder"
Case Is = 6
lstResults.RowSource = "PullHandle"
Case Is = 7
lstResults.RowSource = "RTDHandle"
Case Is = 8
lstResults.RowSource = "DoorCloser"
Case Is = 9
lstResults.RowSource = "PushPlate"
Case Is = 10
lstResults.RowSource = "KickPlate"
Case Is = 11
lstResults.RowSource = "Signage"
Case Is = 12
lstResults.RowSource = "ThumbTurnIndicator"
Case Is = 13
lstResults.RowSource = "DigitalLock"
Case Is = 14
lstResults.RowSource = "CylinderPull"
Case Is = 15
lstResults.RowSource = "FloorSocket"
Case Is = 16
lstResults.RowSource = "DoorStop"
End Select
End Sub
Private Sub lstResults_Click()
'dim the variables
Dim i As Integer
Dim fPath As String
Dim Pic As String
'set the file path
fPath = ThisWorkbook.Path & "\" & "Ironmongery Images"
i = Me.lstResults.ListIndex
On Error Resume Next
'display the picture
Me.Image1.Picture = LoadPicture(fPath & "\" & Me.lstResults.Column(0, i) & ".jpg")
'If picture is not available
If Err = 53 Then
Me.Image1.Picture = LoadPicture(fPath & "\" & "Ironmongery Images" & "\" & "NoPicture.jpg")
End If
'reset error handler
On Error GoTo 0
End Sub
Private Sub txtamount_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If Trim(txtamount.Value) = "" And Me.Visible Then
MsgBox "Cannot Be Empty", vbCritical, "Error"
Cancel = True
txtamount.BackColor = vbRed
Else
txtamount.BackColor = vbWhite
End If
End Sub
Private Sub UserForm_Initialize()
cboxType.RowSource = "ProductType"
End Sub
Private Sub UserForm_QueryClose(Cancel As Integer, _
CloseMode As Integer)
If CloseMode = vbFormControlMenu Then
Cancel = True
MsgBox "Please use the Close button!"
End If
End Sub
Display More