Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

combo box

Status
Not open for further replies.

vlitim

Programmer
Sep 2, 2000
393
0
0
GB
I am using the below code to get a list of staff from a table. What I want to do is havet the first list Item Displayed and being Where adostaff("StaffID") = adoPrimaryRS("StaffNo").

basically how do you do
if adostaff("StaffID") = adoPrimaryRS("StaffNo") then
<option value=&quot;&quot; Selected>name
else
<option value=&quot;&quot;>name
end if

----------------------

Set adoPrimaryRS = New Recordset
adoPrimaryRS.Open &quot;select id,description,date,days,hours,mins,staffNo,Department,periodNo from Maintenance WHERE jobno=&quot; & JobID & &quot; ORDER by ID&quot;, db, adOpenStatic, adLockOptimistic

' Get the List of Staff and The Current Staff Member
Set adostaff = New Recordset
adostaff.Open &quot;select fname,sname,staffID from staff ORDER by fname&quot;, db, adOpenStatic, adLockOptimistic
Do While Not adostaff.EOF
CmbStaff.AddItem (adostaff(&quot;fname&quot;) & &quot; &quot; & adostaff(&quot;sname&quot;))
adostaff.MoveNext
Loop
adostaff.Close
 
If you use a datacombo instead of a combo box you have the opertunity to set both a datasource *and* a recordsource. You could set your datasource to be your adoprimaryrs and the boundcolumn would be staffno. This will save your staffno in memory. Then set your rowsource to be your adostaff and your listfield to be the staffname. ( you can do this in the properties of the datacombo control).

Or you could do it the other way arouned. But the point of the datacombo is to let you go to another recordset to specify what shows up in the recordset you are using for the combo box.


If you have VB Desktop exam cram book, check out page 258.
 
Do While Not adostaff.EOF
CmbStaff.AddItem (adostaff(&quot;fname&quot;) & &quot; &quot; & adostaff(&quot;sname&quot;))
CmbStaff.ItemData(CmbStaff.NewIndex)=adostaff(&quot;staffID&quot;)
adostaff.MoveNext
Loop
Later You can find any Item in CmbStaff, using ItemData
For i=0 to CmbStaff.ListCount-1
if cmbStaff.ItemData(i)= adoPrimaryRS(&quot;staffNo&quot;) then
cmbStaff.ListIndex=i
cmbStaff.Text=cmbStaff.ListItem(i)
Exit For
End if
next I
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top