J
Jennifer
Hi Guys,
I asked asked this question awhile back and wasn't able to find the answer I
was looking for. So I thought I would try again, hopefully with a clearer
explanation.
1. I have a userform that contains a combo box and a listbox.
2. I select from the combo box a farmers market location
3. The list box then fills with any entries from the database that match the
combo box.
4.I can select using the curser any entry in the listbox
5.I want to add a delete button that deletes the selected entry in the list
box
6.Here is the catch: I was given a code that deletes the entry from the
listbox ONLY
7.MY NEED IS FOR THE BUTTON TO ALSO DELETE IT FROM THE DATABASE.
That's it! Thank you! I have also added what code I have. Again, Thank you.
Jennifer
Option Explicit
Private Const Sourcename As String = "ProdTable"
Private Source As Range
Private Sub cmdClose_Click()
Unload Me
End Sub
Private Sub UserForm_Initialize()
Set Source = Range(Sourcename)
LoadMarkets
End Sub
Private Sub LoadMarkets()
Dim markets As New Scripting.Dictionary
Dim index As Long
Dim market As String
For index = 2 To Source.Rows.Count
market = Source.Cells(index, 1)
If Not markets.Exists(market) Then
markets.Add market, market
cmbMarket.AddItem market
End If
Next
End Sub
Private Sub cmbMarket_Change()
LoadMarketData
End Sub
Private Sub LoadMarketData()
Dim market As String
Dim index As Long
market = cmbMarket.Value
With lstProducts
.Clear
For index = 2 To Source.Rows.Count
If Source.Cells(index, 1).Value = market Then
.AddItem Source.Cells(index, 2)
.List(.ListCount - 1, 1) = Source.Cells(index, 3)
.List(.ListCount - 1, 2) = Source.Cells(index, 4)
End If
Next
End With
End Sub
I asked asked this question awhile back and wasn't able to find the answer I
was looking for. So I thought I would try again, hopefully with a clearer
explanation.
1. I have a userform that contains a combo box and a listbox.
2. I select from the combo box a farmers market location
3. The list box then fills with any entries from the database that match the
combo box.
4.I can select using the curser any entry in the listbox
5.I want to add a delete button that deletes the selected entry in the list
box
6.Here is the catch: I was given a code that deletes the entry from the
listbox ONLY
7.MY NEED IS FOR THE BUTTON TO ALSO DELETE IT FROM THE DATABASE.
That's it! Thank you! I have also added what code I have. Again, Thank you.
Jennifer
Option Explicit
Private Const Sourcename As String = "ProdTable"
Private Source As Range
Private Sub cmdClose_Click()
Unload Me
End Sub
Private Sub UserForm_Initialize()
Set Source = Range(Sourcename)
LoadMarkets
End Sub
Private Sub LoadMarkets()
Dim markets As New Scripting.Dictionary
Dim index As Long
Dim market As String
For index = 2 To Source.Rows.Count
market = Source.Cells(index, 1)
If Not markets.Exists(market) Then
markets.Add market, market
cmbMarket.AddItem market
End If
Next
End Sub
Private Sub cmbMarket_Change()
LoadMarketData
End Sub
Private Sub LoadMarketData()
Dim market As String
Dim index As Long
market = cmbMarket.Value
With lstProducts
.Clear
For index = 2 To Source.Rows.Count
If Source.Cells(index, 1).Value = market Then
.AddItem Source.Cells(index, 2)
.List(.ListCount - 1, 1) = Source.Cells(index, 3)
.List(.ListCount - 1, 2) = Source.Cells(index, 4)
End If
Next
End With
End Sub