Setting display value in combo box

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am populating a combo box and then want to set the default displayed value to the first item not the null item

THis is my code
strSQL = "SELECT grpmas.itmg_nm, grpmas.itmg_ds FROM grpmas " & _
"WHERE grpmas.itmg_nm Not Like 'CLN' And grpmas.itmg_nm Not Like 'FIN' And " & _
"grpmas.itmg_nm Not Like 'FRT' And grpmas.itmg_nm Not Like 'FTIN' And " & _
"grpmas.itmg_nm Not Like 'HIR' And grpmas.itmg_nm Not Like 'RNT' " & _
"ORDER BY grpmas.itmg_ds;"
Set rsProd = db.OpenRecordset(strSQL)
Me.cboProdGp.AddItem "*;All Groups"
If Not rsProd.EOF Then rsProd.MoveFirst
Do Until rsProd.EOF
Me.cboProdGp.AddItem rsProd!itmg_nm & ";" & rsProd!itmg_ds
rsProd.MoveNext
Loop
' Trying to set it to first row with bound value of "*"
Me.cboProdGp.ListIndex (0)

It should be so easy but I can't work it out.
Thanks
Stephen
 
The standard Access combo box does not have the AddItem
method. Try using the following to set it's RowSource
Me.cboProdGp.RowSource = "SELECT '*' As itmg_nm , 'All
Groups' As itmg_ds FROM grpmas UNION SELECT grpmas.itmg_nm,
grpmas.itmg_ds FROM grpmas WHERE grpmas.itmg_nm Not Like
'CLN' And grpmas.itmg_nm Not Like 'FIN' And grpmas.itmg_nm
Not Like 'FRT' And grpmas.itmg_nm Not Like 'FTIN' And
grpmas.itmg_nm Not Like 'HIR' And grpmas.itmg_nm Not Like
'RNT' ORDER BY grpmas.itmg_ds;

To set the value to the first item, try
Me.cboProdGp.Value = Me.cboProdGp.ListIndex (0)

Depending on the values for itmg_ds, you may find that the
'All Groups' is no longer the first item in the list. You
may need to make it ' All Groups'.

Hope This Helps
Gerald Stanley MCSD
-----Original Message-----
I am populating a combo box and then want to set the
default displayed value to the first item not the null item
THis is my code
strSQL = "SELECT grpmas.itmg_nm, grpmas.itmg_ds FROM grpmas " & _
"WHERE grpmas.itmg_nm Not Like 'CLN' And
grpmas.itmg_nm Not Like 'FIN' And " & _
 
Back
Top