userform problems

O

Oboy

Hi all,

I open a sheet that shows the number of items in stock and their value for
each item. When I buy or sell another item (even something new that doesn't
exists in stock) I need to update my inventory. I made 2 userforms to
collect info buy/sell and use the info to do that but no luck :(

Form1 is for sold items with a txt box where you can only choose what's in
the inventory and not add any item, an OK and clear button.
Form2 for buying, adding to the inventory where you see a list and can add
to it.

Userforms don't load and I get errors ... "userform empty ",etc.
Have lost days on this problem ... ok sorry I'm dumb:)

PLS need to know:
1) the correct way for dynamicly (?) populating the combobox and the
textlist from a table in a worksheet and retrieving the values selected or
added to the forms.
2) How do I load, show, and close the 2 populated forms.

Any help appreciated.
 
J

Jeff

Hi Oboy, First we'll address your second question,
to show userforms use the .show method like this

Private Sub Workbook_Open()
'Insert your form names after Call statment
Call FrmSoldItems.Show(vbModeless)
Call FrmDummy.Show(vbModeless)
End Sub

This will show both form at the same time and allow you to swtich between
them.

On to your first queston. There is about a a handfull of ways to Fill a
combobox/Listbox control. Here is my solution,

Private Sub UserForm_Initialize()
'Your combobox Name
With cboSoldItems
'if no columnheads change to false
.ColumnHeads = True

'Show Item & Qty
.ColumnCount = 2

'Adjust to fit your values
.ColumnWidths = 50

'Pass the Worksheet to "GetRowSource" to add
'values to your comboBox
.RowSource = GetRowSource(Worksheets("Sheet1"))
End With

' Example for listbox
With lboInventory
.ColumnHeads = True
.ColumnCount = 2
.ColumnWidths = 50
.RowSource = GetRowSource(Worksheets(1))
End With

End Sub

Public Function GetRowSource(ByVal ws As Worksheet) As String
Dim LastRow As Long

'Finds last row from bottom up in column 1("A")
LastRow = ws.Cells(Rows.Count, 1).End(xlUp).Row

'assumes first two columns contain you values,
'and first row contains columnheads
GetRowSource = ws.Range("A2", "B" & LastRow).Address
End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top