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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ok a new issue in my Word template

Status
Not open for further replies.

Dwight3238

Technical User
Aug 19, 2003
11
US
ok a new issue in my Word template VBA project. i'm trying to have the records from my database display in a combo box. earlier in my code i opened this database and grabed a single record. now when i try to grab all records for my list i get the single record from before repeated as many times as there are records.

Here is the code i'm using, what am i missing?
dbMain.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Persist Security Info=False;" & "Data Source _
=c:\data\PhyList.mdb"
SQL = "SELECT LastName, FullName FROM Phy_List"
rsPhy1.Open SQL, dbMain, adOpenDynamic, adLockOptimistic

phyLName = rsPhy1("LastName")
phyFName = rsPhy1("FullName")

Do While Not rsPhy1.EOF
With cboJobSelection
.AddItem (phyLName & " - " & phyFName)
End With
rsPhy1.MoveNext
Loop
 
Hi,
Because you don’t change the value of your variables:

phyLName = rsPhy1("LastName")
phyFName = rsPhy1("FullName")

Do While Not rsPhy1.EOF
With cboJobSelection
.AddItem (phyLName & " - " & phyFName)
End With
rsPhy1.MoveNext
loop


Try it:

phyLName = rsPhy1("LastName")
phyFName = rsPhy1("FullName")

Do While Not rsPhy1.EOF
With cboJobSelection
.AddItem (phyLName & " - " & phyFName)
End With
rsPhy1.MoveNext
phyLName = rsPhy1("LastName")
phyFName = rsPhy1("FullName")


loop



Jean-Paul
Montreal
jp@solutionsvba.com
mtljp2@sympatico.ca
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top