-
Mar 4th, 2018, 11:06 AM
#1
Thread Starter
Junior Member
[RESOLVED] Filling combo box with with a filter from a different combo box
Hello,
I use Visual studio 2015, and Access 2016 and I am trying to fill a combo box with a select statement with a filter from another combo box.
Such as if combo box 1 contains State(AK) then In combo box 2 I want to show counties that are in that state (4)from the complete list of counties (3077). Don't want to show the Number I want to show the name of county. Yes the database is there and the table does have state(by 2 letter abrev. and the county by name) Here is the code for the State that works, and the County that doesn't :
Public Sub GetHState()
'Gets the State's to show in comboBox his state
Dim mcall = lblCall.Text
Dim ds As New DataSet
Dim dt As New DataTable
ds.Tables.Add(dt)
Dim da As New OleDbDataAdapter
'------------ FROM HERE THE NEXT LINES SET UP THE CONNECTION STRING FOR USER'S DATABASE------------------
Dim strFilePrefix = "NetControl"
Dim strFileSuffix = ".accdb"
Dim databaseFile As String = "C:\RRLogger Data\" & strFilePrefix & strFileSuffix
Dim conString = "Provider = Microsoft.Ace.OLEDB.12.0; Data Source= " & databaseFile
'--------------------------------------------------------------------------------------------------------------
con.ConnectionString = conString
con.Open()
da = New OleDbDataAdapter("Select State From State1", con) '
da.Fill(dt)
con.Close()
'CLEar combobox
cmbHState.Items.Clear()
'FILL COMBOBOX
For Each R As DataRow In dt.Rows
cmbHState.Items.Add(R("State"))
Next
'DISPLAY FIRST RECORD
cmbHState.Text = CType(dt.Rows(0).Item(0), String)
End Sub
Private Sub GetMCounty()
' Dim Access As New DbControl
'Dim mcall = lblCall.Text
Dim ds As New DataSet
Dim dt As New DataTable
ds.Tables.Add(dt)
Dim da As New OleDbDataAdapter
'------------ FROM HERE THE NEXT LINES SET UP THE CONNECTION STRING FOR USER'S DATABASE------------------
Dim strFilePrefix = "NetControl"
Dim strFileSuffix = ".accdb"
Dim databaseFile As String = "C:\RRLogger Data\" & strFilePrefix & strFileSuffix
Dim conString = "Provider = Microsoft.Ace.OLEDB.12.0; Data Source= " & databaseFile
'--------------------------------------------------------------------------------------------------------------
con.ConnectionString = conString
con.Open()
da = New OleDbDataAdapter("SELECT County FROM County WHERE State = cmbhState.Text", con)
da.Fill(dt)
con.Close()
'CLEar combobox
cmbMCounty.Items.Clear()
For Each R As DataRow In dt.Rows
cmbMCounty.Items.Add(R("County"))
Next
'DISPLAY FIRST RECORD
End Sub
When I run it I get the error...... Message "No value given for one or more required parameters." String
Please help?????
Last edited by MikeDelke; Mar 4th, 2018 at 11:10 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|