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

Help with a loop

Status
Not open for further replies.

hunterlpr

Technical User
Nov 15, 2002
15
US
Dim rs As DAO.Recordset
Dim vartemp As Variant

Hi, I need help making the 2nd part of my if statement to loop. I'm getting the results I wanted but used the goto next record to check the next one however I need to check all records. How would I create a loop to do this. Thanks.


vartemp = DLookup("[category]", "table1", "[category]=forms![form1]![category]")
If Me.Obtained = True Then
MsgBox ("made it past obtained is true")
vartemp = Forms!form1!category
DoCmd.GoToRecord , , acNext

If category = vartemp Then
MsgBox ("made it past vartemp")
Obtained = True
MsgBox ("made it past obtained=true")
End If

End If
 
What do you mean loop thru? I would use a string to build the "SELECT...;" statement I wanted and then set the form's rowsource to that value and see only the one's that matched the criterion. Another cmd button might be used to set the form's data source to "ALL"

Rollie E
 
I need it to repeat that 2nd if statement until no more matches. something like dowhile until no match.
 
Post your email address or email me ans ask and I will code up an example for you.


rollie@bwsys.net
 
Thanks for your reply Rolliee. I've almost got it. I used some VB and then invoked an update query. But what I'd now like to do is skip the query and write it into my VB. Below is my Vb and following is the SQL which Im not sure how to change into VB

Dim rst As Object
Dim vartemp As Variant
Dim stDocName As String
stDocName = "Table1 Query"
Dim vartemp1 As Variant

If Me.Obtained = True And Me.competency Like "select all" Then
vartemp = category
vartemp1 = subcategory
category = vartemp
subcategory = vartemp1
stDocName = "Table1 Query"
DoCmd.OpenQuery stDocName, acNormal, acEdit



End If


UPDATE Table1 SET Table1.Obtained = True
WHERE (((Table1.category)=[forms]![form1]![category]) AND ((Table1.subcategory)=[forms]![form1]![subcategory]));

I know this is pretty simple but I haven't been at it that long. This is a practice db so I dont mess up the original. Plus the networks down and can't get to it. Thanks Again!
 
docmd.runSQL (UPDATE Table1 SET Table1.Obtained = True
WHERE (((Table1.category)=[forms]![form1]![category]) AND ((Table1.subcategory)=[forms]![form1]![subcategory]));)

HTH,
ERic
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top