matt_swinburne
asked on
Combo boxes database
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.OL EDB.4.0;Da ta 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)
Try
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
MsgBox(Ex.Message)
End Try
DA.Fill(dt)
dvtwo = dt.DefaultView
cmtwo = CType(Me.BindingContext(Da taSet11), CurrencyManager)
dv = dt.DefaultView
cm = CType(Me.BindingContext(dv ), CurrencyManager)
'Bind Textboxes
TxtClient.DataBindings.Add ("Text", dv, "ClientName")
TxtMatterNumber.DataBindin gs.Add("Te xt", dv, "MatterNo")
TxtCloseDate.DataBindings. Add("Text" , dv, "CloseDate")
TxtNotes.DataBindings.Add( "Text", dv, "Notes")
TxtBox.DataBindings.Add("T ext", dv, "BoxNumber")
TxtDateIn.DataBindings.Add ("Text", dv, "DateIn")
TxtStoreDate.DataBindings. Add("Text" , dv, "StoreDate")
TxtDateRemoved.DataBinding s.Add("Tex t", dv, "RemoveDate")
TxtDestroyDate.DataBinding s.Add("Tex t", dv, "DestroyDate")
'Load Originating Location Combo
CmbLocation.DataSource = DataSet11.Tables("Location s")
CmbLocation.DisplayMember = "LocationName"
CmbLocation.ValueMember = "LocationID"
CmbLocation.DataBindings.A dd("select edvalue", DataSet11, "Main.LocationID")
'Load FeeEarner ComboBox
CmbFeeEarner.DataSource = DataSet11.Tables("FeeEarne r")
CmbFeeEarner.DisplayMember = "FeeEarnerName"
CmbFeeEarner.ValueMember = "FeeEarnerID"
CmbFeeEarner.DataBindings. Add("selec tedvalue", DataSet11, "Main.FeeEarnerID")
'Load MatterType Combobox
CmbMatter.DataSource = DataSet11.Tables("Matter")
CmbMatter.DisplayMember = "MatterTypeName"
CmbMatter.ValueMember = "MatterTypeID"
CmbMatter.DataBindings.Add ("selected value", DataSet11, "Main.MatterTypeID")
'Load Status Combobox
CmbStatus.DataSource = DataSet11.Tables("Status")
CmbStatus.DisplayMember = "StorageName"
CmbStatus.ValueMember = "StatusID"
CmbStatus.DataBindings.Add ("selected value", DataSet11, "Main.StatusID")
'Load Office Combobox
CmbOffice.DataSource = DataSet11.Tables("Offices" )
CmbOffice.DisplayMember = "OfficeName"
CmbOffice.ValueMember = "OfficeID"
CmbOffice.DataBindings.Add ("selected value", DataSet11, "Main.OfficeID")
End Sub
Private Sub NavigationButtons_Click(By Val 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
fs.ShowDialog()
End Select
End Sub
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.OL
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)
Try
DbMain.Fill(DataSet11, "Main")
DbLocations.Fill(DataSet11
DbMatter.Fill(DataSet11, "Matter")
DbFeeEarner.Fill(DataSet11
DbOffice.Fill(DataSet11, "Offices")
DbStatus.Fill(DataSet11, "Status")
Catch Ex As Exception
MsgBox(Ex.Message)
End Try
DA.Fill(dt)
dvtwo = dt.DefaultView
cmtwo = CType(Me.BindingContext(Da
dv = dt.DefaultView
cm = CType(Me.BindingContext(dv
'Bind Textboxes
TxtClient.DataBindings.Add
TxtMatterNumber.DataBindin
TxtCloseDate.DataBindings.
TxtNotes.DataBindings.Add(
TxtBox.DataBindings.Add("T
TxtDateIn.DataBindings.Add
TxtStoreDate.DataBindings.
TxtDateRemoved.DataBinding
TxtDestroyDate.DataBinding
'Load Originating Location Combo
CmbLocation.DataSource = DataSet11.Tables("Location
CmbLocation.DisplayMember = "LocationName"
CmbLocation.ValueMember = "LocationID"
CmbLocation.DataBindings.A
'Load FeeEarner ComboBox
CmbFeeEarner.DataSource = DataSet11.Tables("FeeEarne
CmbFeeEarner.DisplayMember
CmbFeeEarner.ValueMember = "FeeEarnerID"
CmbFeeEarner.DataBindings.
'Load MatterType Combobox
CmbMatter.DataSource = DataSet11.Tables("Matter")
CmbMatter.DisplayMember = "MatterTypeName"
CmbMatter.ValueMember = "MatterTypeID"
CmbMatter.DataBindings.Add
'Load Status Combobox
CmbStatus.DataSource = DataSet11.Tables("Status")
CmbStatus.DisplayMember = "StorageName"
CmbStatus.ValueMember = "StatusID"
CmbStatus.DataBindings.Add
'Load Office Combobox
CmbOffice.DataSource = DataSet11.Tables("Offices"
CmbOffice.DisplayMember = "OfficeName"
CmbOffice.ValueMember = "OfficeID"
CmbOffice.DataBindings.Add
End Sub
Private Sub NavigationButtons_Click(By
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
fs.ShowDialog()
End Select
End Sub
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?
ASKER
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
Thanks for the help
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Bob