Combo boxes database

Posted on 2005-05-09
Last Modified: 2010-04-23
I am creating a front end for an access database which displays data in text and combo boxes.  When you click a search button on the main form it opens another form which has a combobox on so that you can select to search by name, or box number.  Then when you have entered your data and selected what to search by I would like the application to switch back to the main form and update the text/comboboxes.  

The combo boxes dont scroll through the records.  I tried to sort this with the following, (didnt work).

Dim dt As New DataTable
    Public dv As DataView
    Public dvtwo As DataView
    Dim cm As CurrencyManager
    Dim cmtwo As CurrencyManager
    Dim CurrentRecord As Integer
    Dim Constr As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\Matt\Desktop\File Tracker.mdb;Persist Security Info=False"


    Public Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Dim DA As New OleDbDataAdapter("Select * From Main", Constr)

            DbMain.Fill(DataSet11, "Main")
            DbLocations.Fill(DataSet11, "Locations")
            DbMatter.Fill(DataSet11, "Matter")
            DbFeeEarner.Fill(DataSet11, "FeeEarner")
            DbOffice.Fill(DataSet11, "Offices")
            DbStatus.Fill(DataSet11, "Status")

        Catch Ex As Exception
        End Try

        dvtwo = dt.DefaultView
        cmtwo = CType(Me.BindingContext(DataSet11), CurrencyManager)
        dv = dt.DefaultView
        cm = CType(Me.BindingContext(dv), CurrencyManager)

        'Bind Textboxes

        TxtClient.DataBindings.Add("Text", dv, "ClientName")
        TxtMatterNumber.DataBindings.Add("Text", dv, "MatterNo")
        TxtCloseDate.DataBindings.Add("Text", dv, "CloseDate")
        TxtNotes.DataBindings.Add("Text", dv, "Notes")
        TxtBox.DataBindings.Add("Text", dv, "BoxNumber")
        TxtDateIn.DataBindings.Add("Text", dv, "DateIn")
        TxtStoreDate.DataBindings.Add("Text", dv, "StoreDate")
        TxtDateRemoved.DataBindings.Add("Text", dv, "RemoveDate")
        TxtDestroyDate.DataBindings.Add("Text", dv, "DestroyDate")

        'Load Originating Location Combo
        CmbLocation.DataSource = DataSet11.Tables("Locations")
        CmbLocation.DisplayMember = "LocationName"
        CmbLocation.ValueMember = "LocationID"
        CmbLocation.DataBindings.Add("selectedvalue", DataSet11, "Main.LocationID")

        'Load FeeEarner ComboBox
        CmbFeeEarner.DataSource = DataSet11.Tables("FeeEarner")
        CmbFeeEarner.DisplayMember = "FeeEarnerName"
        CmbFeeEarner.ValueMember = "FeeEarnerID"
        CmbFeeEarner.DataBindings.Add("selectedvalue", DataSet11, "Main.FeeEarnerID")

        'Load MatterType Combobox
        CmbMatter.DataSource = DataSet11.Tables("Matter")
        CmbMatter.DisplayMember = "MatterTypeName"
        CmbMatter.ValueMember = "MatterTypeID"
        CmbMatter.DataBindings.Add("selectedvalue", DataSet11, "Main.MatterTypeID")

        'Load Status Combobox
        CmbStatus.DataSource = DataSet11.Tables("Status")
        CmbStatus.DisplayMember = "StorageName"
        CmbStatus.ValueMember = "StatusID"
        CmbStatus.DataBindings.Add("selectedvalue", DataSet11, "Main.StatusID")

        'Load Office Combobox
        CmbOffice.DataSource = DataSet11.Tables("Offices")
        CmbOffice.DisplayMember = "OfficeName"
        CmbOffice.ValueMember = "OfficeID"
        CmbOffice.DataBindings.Add("selectedvalue", DataSet11, "Main.OfficeID")

    End Sub

Private Sub NavigationButtons_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnFirst.Click, BtnLast.Click, BtnNext.Click, BtnPrevious.Click, BtnMainSearch.Click
        Select Case sender.Name
            Case "BtnFirst"

                cm.Position = 0

                cmtwo.Position = 0

            Case "BtnPrevious"

                cm.Position -= 1
                cmtwo.Position -= 1

            Case "BtnNext"

                cm.Position += 1
                cmtwo.Position += 1

            Case "BtnLast"

                cm.Position = dv.Count - 1
                cmtwo.Position = dv.Count - 1

            Case "BtnMainSearch"
                Dim fs As New Search
                fs.Owner = Me

        End Select

    End Sub
Question by:matt_swinburne
    LVL 96

    Expert Comment

    by:Bob Learned
    What are the combo boxes doing?  Displaying nothing?  Displaying incorrect text?

    LVL 13

    Expert Comment

    What exactly do you mean the combo boxes don't sort through the records?  Do you mean they aren't getting any data from the database?

    Author Comment

    The combo boxes use an IDno in the table main to look up the, for example, locations name kept in the table locations.  The code picks up this but wont cycle through the records.  (Basically the coding for the navigation buttons doesnt work, i think!)

    Thanks for the help

    LVL 96

    Accepted Solution

    I am confused.  Why do you have two CurrencyManagers?   Why do you bind some controls to the DataView, and others to the DataSet?


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Suggested Solutions

    I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
    If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    7 Experts available now in Live!

    Get 1:1 Help Now