Results 1 to 1 of 1

Thread: [RESOLVED] I need help filtering into a Combobox

Threaded View

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2008
    Posts
    104

    Resolved [RESOLVED] I need help filtering into a Combobox

    Hello Everyone:

    I need some help filtering and displaying data into a combobox; here is my scenerio:
    I am using vb2005, for a database, i am using MS Access 2003.

    I have a table named 'Departmernt" with an ID, Code and Description.
    I have an add new record form where I have multiple comboboxes, one of the comboboxes is called "Department", just above the Department combobox, I have added two radio boxes, one is called " HR Department", the other "Payroll Department", within each department they may use the same item with the same name (description), but when is display on the "Department" combo box dipending on the option they select from the dropdown, is suppost to give then a different options, ones that they are associated only with HR and the other for Payroll.
    I have everything in place already and so far is working fine, what I need help with is filtering only the items that are associated with the "HR Department" when they click on the HR radiobox and the same for the Payroll.

    I have the folllowing code that does the work of filtering the code for me, but it only displays one when i look in the dropdown of my combobox.

    What am I missing?

    On the add New record form I have added to text boxes set as not visible:that I use on my select statament:
    TexAddHR.Text = "HR"
    TexAddPayroll.Text = "Payroll"

    In my table I have the code and description as follow:
    This is just an example:
    Code = HRPaper Description = Paper
    Code = PayrollPaper Description = Paper
    Code = HRform Description = Form
    Code = PayrollForm Description = Form
    If I select the HR radiobox I want only to for the HR item to display in the Department combobox

    Code:
    Private Sub RadioSrHR_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioSrHR.CheckedChanged
            CmbSrDistrict.Items.Clear()
            '^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    
            Dim cn As OleDbConnection
            Dim cmd As OleDbCommand
            Dim dr As OleDbDataReader
           CmbSrDistrict.Items.Clear()
    
    cn = New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Accessdatabase.mdb;Persist Security Info=False")
    cn.Open()
    
    cmd = New OleDbCommand("select * FROM Departmernt WHERE CODE LIKE '%" & TexSrHR.Text & "%'", cn)
    dr = cmd.ExecuteReader
    
    While dr.Read()
                Me.CmbSrDistrict.Items.Add("@HR")          
                
    End While
    
    cn.Close()        
    End Sub
    Last edited by MrBlackKnight; Feb 5th, 2009 at 09:55 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
  •  



Click Here to Expand Forum to Full Width