?
Solved

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

Posted on 2003-03-20
6
Medium Priority
?
212 Views
Last Modified: 2010-05-01
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
Comment
Question by:Ezhil7
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
6 Comments
 
LVL 11

Expert Comment

by:supunr
ID: 8179187
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
 
LVL 1

Accepted Solution

by:
Sankar_V earned 150 total points
ID: 8179292
How do u connect to ur Database??

Through Data Environment...OR

Through Code!


0
 
LVL 1

Expert Comment

by:Sankar_V
ID: 8179297
How do u connect to ur Database??

Through Data Environment...OR

Through Code!


0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:Ezhil7
ID: 8179426
i connected the database by coding(ADODB)
0
 
LVL 1

Expert Comment

by:Sankar_V
ID: 8179473
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
 
LVL 1

Expert Comment

by:Sankar_V
ID: 8179477
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

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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month10 days, 20 hours left to enroll

770 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