adding str to label

osi33015
11-10-2004, 11:56 AM
Hi! i have a small database and amworking with the Table Called Employees

what i want to do is add all the records from the Employees table to labels

here is some code so that you will undestand me better

Set MyRecSet = MyConn.Execute("SELECT FirstName, LastName, EmpID,DepNum,SSS FROM Employees")

Do Until MyRecSet.EOF
strName = MyRecSet!FirstName
strlastname = MyRecSet!LastName
strEmpId = MyRecSet!EmpID
strDepId = MyRecSet!DepNum
strSSS = MyRecSet!SSS

MyRecSet.MoveNext
Loop

lblname.Caption = strName
lbllastname.Caption = strlastname
lblEmpID.Caption = strEmpId
lblDepNum.Caption = strDepId
lblSSS.Caption = strSSS

lblname2.Caption = strName
lbllastname2.Caption = strlastname
lblEmpID2.Caption = strEmpId
lblDepNum2.Caption = strDepId
lblSSS2.Caption = strSSS

In lblname2 and the rest, what it comes out is the same as lblname, i would like to keep on adding the next row from the Employees table

Thank you in advance

00100b
11-10-2004, 12:30 PM
Move the assignment of the values to the Caption properties inside the loop through the recordset.

The way it is coded now, all labels would receive the values from the last record only since the string variables are getting overwritten with each iteration through the loop.

It would also be better to use control arrays. For example, a control array for lblName with the value of the Index properties being 0 to n.

Then, using a counter variable within the loop, you could do something like:

Dim lngCounter As Long

Set MyRecSet = MyConn.Execute("SELECT FirstName, LastName, EmpID,DepNum,SSS FROM Employees")

Do Until MyRecSet.EOF

lblName(lngCounter).Caption = MyRecSet!FirstName
lblLastName(lngCounter).Caption = MyRecSet!LastName
lblEmpId(lngCounter).Caption = MyRecSet!EmpID
lblDepId(lngCounter).Caption = MyRecSet!DepNum
lblSSS(lngCounter).Caption = MyRecSet!SSS

MyRecSet.MoveNext
lngCounter = lngCounter + 1

Loop

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum