Loop Examples

alastair69

Registered User.
Local time
Today, 02:51
Joined
Dec 21, 2004
Messages
560
Does anybody have any examples of loop, which will find data in a query and then show it as one line (string), listing all the data in one row.

Thanks inadvance

Alastair
 
I wrote this to show all employee's titles in a string:

Code:
Public Function fShowTitles(lngEmploymentID As Long) As String
On Error GoTo Err_fShowTitles
'This function shows Employment Titles in a string format

    Dim dbs As DAO.Database
    Dim snp As DAO.Recordset
    Set dbs = CurrentDb
    Set snp = dbs.OpenRecordset("qryEmploymentTitles", dbOpenSnapshot)
    snp.MoveFirst

    Do Until snp.EOF
        If snp![EmploymentID] = lngEmploymentID Then
            fShowTitles = fShowTitles & IIf(fShowTitles = "", "", "; ") & snp!Title
        End If
    snp.MoveNext
    Loop
    
    snp.Close
    dbs.Close

Exit_fShowTitles:
    Exit Function
Err_fShowTitles:
    MsgBox Err.Description, vbCritical, "Error " & Err.Number
    Resume Exit_fShowTitles
End Function
 

Users who are viewing this thread

Back
Top Bottom