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

Passing Function Result to a Table

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
DoCmd.OpenQuery "qryAppendEmployeesQuery"
ActiveEmployeeName = rstError!LastName
MsgBox "Last Name is: " & ActiveEmployeeName
rstError.MoveNext
Loop
rstError.Close
Set rstError = Nothing
End Function


I appreciate your help. Thanks,
Sam
 
Despite the description, I'm still confused about what you expect to put where. In brief, the function will (should) return a single (string) value each time it is called (the "As String" in the first line). It should cycle through the entire recordset (rstError), and display some string (LastName?) in the msg boxes for each record, but these are probably just nusicances, as you need to acknowledge each one two times, and then they are discarded. Another (probably un-deisreable) side effect is the instantiation of the query (qryAppendEmployeesQuery) once -for each record in rstError. If you are using the obvious naming convention and hte query is constructed propsely, this is where SOME recordset is accumulating SOME value(s) (the "Append" part). As to wht you do with the return value of the Function, that is (clearly?) outside this thread, as the usage / implementation is not shown.


MichaelRed
m.red@att.net

There is never time to do it right but there is always time to do it over
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top