Dustin Stanley
asked on
MS Access VBA For Each Loop. How Do I Set The Criteria Such As Where [ID] = [ID]?
I have 2 loops. The "For Each Loop " is nested in the "Do While Not Loop".
I am needing there to be a Criteria for the "For Each Loop" such as
rst1("SkuID").value = rst2("SkuID").value
This is for appending several different Strings from "qryImageStep1"to a file For Each record that matches the "SkuID" in "qryAddFixedPriceItem".
How Do I Set The Criteria for the "For Each Loop"?
Thanks!
Dim rst1 As DAO.Recordset
Dim rst2 As DAO.Recordset
Set rst1 = CurrentDb.OpenRecordset("qryAddFixedPriceItem", dbOpenSnapshot)
Set rst2 = CurrentDb.OpenRecordset("qryImageStep1", dbOpenSnapshot)
Dim URL As Variant
For Each URL In rst2
I am needing there to be a Criteria for the "For Each Loop" such as
rst1("SkuID").value = rst2("SkuID").value
This is for appending several different Strings from "qryImageStep1"to a file For Each record that matches the "SkuID" in "qryAddFixedPriceItem".
How Do I Set The Criteria for the "For Each Loop"?
Thanks!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Couldn't you use an UPDATE query for this?
ASKER
This is what I am trying to do in the big picture.
I hope this makes sense.
- I am opening a file on my PC and Appending Strings to it in a certain fashion (XML).
- I have to append a long String for Each record in a Query. This is my "Do While Not rst1.EOF Loop".
- I then have to Append Several individual strings to that long String with my "For Each Loop".
- After the last record in the "For Each Loop" then the "Do While Not rst1.EOF Loop" re-loops and it starts back over again.
I hope this makes sense.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you Crystal and Nice Edits ;)
I totally agree with you on limiting the recordset and I didn't think of that or really even knew how to.
I think I am going to do that. Does this look right for that part? Thanks for the help.
OR
I totally agree with you on limiting the recordset and I didn't think of that or really even knew how to.
I think I am going to do that. Does this look right for that part? Thanks for the help.
Dim db As Database
Dim sSQL As String
Set db = CurrentDb
sSQL = "SELECT qryAddFixedPriceItem.* FROM qryAddFixedPriceItem WHERE rst2(""SkuID"") = rst1(""SkuID"");"
Set rst2 = db.OpenRecordset(sSQL, dbOpenSnapshot)
OR
Dim db As Database
Dim sSQL As String
Set db = CurrentDb
sSQL = "SELECT qryAddFixedPriceItem.* FROM qryAddFixedPriceItem WHERE [SkuID] = rst1(""SkuID"");"
Set rst2 = db.OpenRecordset(sSQL, dbOpenSnapshot)
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I'll get this. Thanks!
you're welcome, Dustin ~ happy to help
>> Nice Edits <<
thanks ... you know me too well ;)
>> Nice Edits <<
thanks ... you know me too well ;)