Set a variable to the one field in a recordset object

Sandra Smith
Sandra Smith used Ask the Experts™
on
This is the start of a complicated email, but I am taking it in steps.  I have begun with the outer most loop in that I need to get all the TaskID's from a query, but how to I assign each TaskID to the variable for the loop?  that is, each time through the outside loop, I want to use the TaskID and then move to the next TaskID and use that for the next loop.  
Private Sub cmdGenerate_Click()
'Generate final email to manager
Dim strUpdateHistory As String
Dim strUpdateCurrent As String
Dim strUpdateTitle   As String
Dim qdfUpdateHistory As QueryDef
Dim qdfUpdateCurrent As QueryDef
Dim qdfUpdateTitle   As QueryDef
Dim strTaskID       As String


Set rst = CurrentDb.OpenRecordset("Select TaskID from qryTasks_UpdatesEmail")
'HOW TO SET THE VARIABLE TO THE TASKID FROM THIS SELECT QUERY
With rst
  Do While Not .EOF
  
Set qdfUpdateTitle = CurrentDb.CreateQueryDef("qryUpdateTitle", strUpdateTitle)
DoCmd.OpenQuery "qryUpdateTitle"
DoCmd.Close acQuery, "qryUpdateTitle"

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2016
Commented:
Set rst = CurrentDb.OpenRecordset("Select TaskID from qryTasks_UpdatesEmail")
'HOW TO SET THE VARIABLE TO THE TASKID FROM THIS SELECT QUERY
With rst
  Do Until .EOF
        strTaskID=rs!TaskID

       ' your codes here to process whatever concerning the TaskID
      .movenext
  Loop
End with
Sandra SmithRetired

Author

Commented:
Capricorn1, thanks.  I had the strTaskID in the wrong place.  As stated, this is teh start of a long and complicated email, so there will more questions soon.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial