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

Pass a query's field Value to Function 1

Status
Not open for further replies.

samn265

Technical User
Feb 12, 2002
35
US
Below is a function to step through a query, one record at a time until the end of the file. I am having a trouble inserting the value of each record “ActiveEmployeeName” to a table. I do not want to append to the table. I just want to have one record in that table which is the value that is passed from the function. I tried to use Make_Table query but it did not work. Any idea of how to do this code?

Function ActiveEmployeeName() As String
Dim rstError As DAO.Recordset
Set rstError = CurrentDb.OpenRecordset("qrySelectCountofActiveEmployees")
Do Until rstError.EOF
'MsgBox "Last Name is: " & rstError!LastName
ActiveEmployeeName = rstError!LastName
MsgBox "Last Name is: " & ActiveEmployeeName
rstError.MoveNext
Loop
rstError.Close
Set rstError = Nothing
End Function


I appreciate your help. Thanks,
Sam
 
Try this minor variation:

Function ActiveEmployeeName() As String
Dim rstError As Recordset
Dim db as DataBase
Dim str as String
Set db = CurrentDb
Set rstError = db.OpenRecordset("qrySelectCountofActiveEmployees")
With rstError
Do Until .EOF
str = !LastName
ActiveEmployeeName = str
Msgbox ActiveEmployeeName
.MoveNext
Loop
End With
Set rstError = Nothing

End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top