Loading a Combo Box with Employee Names

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Akinyemi
    New Member
    • Sep 2006
    • 32

    Loading a Combo Box with Employee Names

    I am developing a Payroll Program. I have created a Database Table in Ms Access 2000. I have placed Text Box controls on my Vb 6 Form including a Combo box.
    I want to fill the combo box with employee names when the Form loads. I have tried to write codes that will do this, but can't get it done.

    Please kindly assist me. What is wrong with the following codes?:
    Private Sub Form_Load()
    With adoSubjects.Rec ordset
    Do Until Not .EOF
    If !SubjectCode <> "" Then
    cboSubjects.Add Item !SubjectCode
    End If
    .MoveNext
    Loop
    .Close
    End With

    Thanks.
    Akinyemi.
  • dorinbogdan
    Recognized Expert Contributor
    • Feb 2007
    • 839

    #2
    What kind of error/problem do you get?

    Comment

    • AlanHill1965
      New Member
      • Feb 2007
      • 8

      #3
      Hi,

      am developing a Payroll Program. I have created a Database Table in Ms Access 2000. I have placed Text Box controls on my Vb 6 Form including a Combo box.
      I want to fill the combo box with employee names when the Form loads. I have tried to write codes that will do this, but can't get it done.

      Please kindly assist me. What is wrong with the following codes?:
      Private Sub Form_Load()
      With adoSubjects.Rec ordset
      Do Until Not .EOF
      If !SubjectCode <> "" Then
      cboSubjects.Add Item !SubjectCode
      End If
      .MoveNext
      Loop
      .Close
      End With

      Thanks.
      Akinyemi.
      Would it not be simpler to set you combo box source to a table/query type then set the rowsource to the SQl string, followed by a requery,

      The following code works for me;

      Private Sub Frame38_Click()

      Dim a As Variant:

      a = Me.Frame38.Valu e

      Select Case a

      Case 1
      strSQL = "SELECT Cat.Index, Cat.Category FROM Cat;"
      Case 2
      strSQL = "SELECT [Position].[Index], [Position].[Position] FROM [Position]; "
      End Select


      Me.List43.RowSo urce = ""
      Me.List43.RowSo urce = strSQL
      Me.List43.Reque ry

      End Sub

      Though this is used in frame, the priciple is the same, as a button is selected the rowsource of the unbound list bow is removed, changed, the refreshed to show the changes.

      This allows you to change the contents of the list box/combo box on the fly, depending on the status of the buttons, The only thing to remember is to include the index of your table (should be numerical), and the format of you list box/combo box you can elect to either show or hide the index number. This can be done as an onload feature, thus giving up to date list in the combo box. I just use the option box selected number and the number of the combo box when refering to an item later on.

      Hope this helps, or maybe I've just got the wrong end of your stick.....

      Alan Hill

      Comment

      Working...