• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 213
  • Last Modified:

adding items in a combobox from a MsAcess database with out duplication?

I am having a data Ms Access database.I have to add the names of the place field from  the table into a combobox control with out duplication in the items.
0
Ezhil7
Asked:
Ezhil7
  • 4
1 Solution
 
supunrCommented:
Private Sub YourFunction()
Combo1.Clear

with rsRecords
   if (.Recordcount > 0)
      .MoveFirst
      Do While (Not .EOF)
          AddToCombo "" & .Fields("FieldName").Value
          .MoveNext
      loop
   end if
End with
End Sub

Private Sub AddToCombo(strItem as String)
    Dim i as Long

    For i = 0 to Combo1.ListCount - 1
        if (UCase(Combo1.List(i)) = UCase(strItem)) then
            ' item found. exit sub
            Exit Sub
        End if
    Next i
    ' item not found.  add to the combo
    Combo1.AddItem strItem
End Sub

Good Luck!
0
 
Sankar_VCommented:
How do u connect to ur Database??

Through Data Environment...OR

Through Code!


0
 
Sankar_VCommented:
How do u connect to ur Database??

Through Data Environment...OR

Through Code!


0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Ezhil7Author Commented:
i connected the database by coding(ADODB)
0
 
Sankar_VCommented:
then here is urs!

just put comboload in form_load()

Dim db As ADODB.Connection
Dim rs As ADODB.Recordset

ensure that the database is in your project folder itself!

Private Sub comboload()
Set db = New ADODB.Connection
Set rs = New ADODB.Recordset
With db
    .Provider = "Microsoft.Jet.OLEDB.4.0"
    .ConnectionString = "Data Source=" & apppath & "urdatabase.mdb"
    .Open
End With
With rs
    .CursorLocation = adUseClient
    .Open "select gradename from grademaster group by gradename", db, adOpenDynamic, adLockBatchOptimistic
End With
If rs.RecordCount > 0 Then
    rs.MoveFirst
        While Not rs.EOF
            Combo1.AddItem rs.Fields(0)
            rs.MoveNext
        Wend
End If
Set rs.ActiveConnection = Nothing
End Sub
0
 
Sankar_VCommented:
then here is urs!

just put comboload in form_load()

Dim db As ADODB.Connection
Dim rs As ADODB.Recordset

ensure that the database is in your project folder itself!

Private Sub comboload()
Set db = New ADODB.Connection
Set rs = New ADODB.Recordset
With db
    .Provider = "Microsoft.Jet.OLEDB.4.0"
    .ConnectionString = "Data Source=" & apppath & "urdatabase.mdb"
    .Open
End With
With rs
    .CursorLocation = adUseClient
    .Open "select your fieldname from your table group by filed name", db, adOpenDynamic, adLockBatchOptimistic
End With
If rs.RecordCount > 0 Then
    rs.MoveFirst
        While Not rs.EOF
            Combo1.AddItem rs.Fields(0)
            rs.MoveNext
        Wend
End If
Set rs.ActiveConnection = Nothing
End Sub
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now