Results 1 to 9 of 9
  1. #1
    Join Date
    Aug 2003
    Posts
    17

    Unanswered: Combobox Defaultvalue

    I'm stumped on this one and it should be easy.

    I have a combobox with a list of items in it pulled from a query. By default, the combobox is blank with the list of items only being visible when you open the drop down. I would like the first item in that list to be the defaultvalue but I can't seem to be able to code it. Here's the code I was trying:

    Private Sub cboCompName_AfterUpdate()
    cboEmpID.RowSource = "qryEmpID2"
    cboEmpID.Requery
    cboEmpID.Value = cboempid. '<---and here's where I'm stumped
    End Sub

    Thank you very much for help

  2. #2
    Join Date
    Jul 2003
    Location
    Michigan
    Posts
    1,941
    You probably need to create a "clone" of the recordset that the combo box uses, and just grab the first record.

    Sub SetComboValue()
    dim rs as dao.recordest, db as database
    set db = currentdb()
    set rs = db.openrecordset("qryEmpId2")
    rs.movefirst
    cboEmpID.Value = rs!EmpID (or whatever the field name is)
    rs.close
    set rs = nothing
    set db = nothing
    End sub
    Inspiration Through Fermentation

  3. #3
    Join Date
    Aug 2003
    Posts
    17
    Thanks for the response.

    I tried this and found out the hard way that I don't have dao objects available as an option. For clarification (as I didn't think of using the recordset as a way around this), I'm using Office 2002 on a Win2k PC. This may have a lot to do with why it didn't work.

    Thanks again!

  4. #4
    Join Date
    Jul 2003
    Location
    Michigan
    Posts
    1,941
    Are you saying that you don't have DAO 3.6 Object Library available as an option in your references library?

    Mark
    Inspiration Through Fermentation

  5. #5
    Join Date
    Aug 2003
    Posts
    17
    That is correct. I'm using a company installation that doesn't have that available and don't have access permissions to have it installed. Is there another workaround that you can think of by chance?

    Thank you ;D

  6. #6
    Join Date
    Jul 2003
    Location
    Michigan
    Posts
    1,941
    What about ADO? You'd have to add some more code, but it would still work. I can't think of a way to do this without using a recordset.
    Inspiration Through Fermentation

  7. #7
    Join Date
    Aug 2003
    Posts
    17
    Yes, ADO I do have

  8. #8
    Join Date
    Jul 2003
    Location
    Michigan
    Posts
    1,941
    OK. Give this a try....

    Sub SetComboValue()
    dim rs as New ADO.recordest, db as database
    dim strSql as string
    'get the SQL statement from your qryEmpID2 and put it in strSql
    strSql = "Select Field1 from...."
    set db = currentdb()
    rs.open strSql, db
    rs.movefirst
    cboEmpID.Value = rs!EmpID (or whatever the field name is)
    rs.close
    set rs = nothing
    set db = nothing
    End sub
    Inspiration Through Fermentation

  9. #9
    Join Date
    Aug 2003
    Posts
    17
    That worked great! True genius from the eyes of this unexperienced db developer! Thank you so much!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •