0

I'm trying to get figure out a work around for this coding.

Essentially this code checks the values of fields in Table CFRRR if program and language match the values in table attendance Programs and Language.

This normal code works. However, if there is not a matching value for language then the code continues to just loop.

I want to adjust the code to go to the next strSQL if there is no matching language, but I can't get it to run through the next strSQL.

I think my error is that I am not writing the IF/THEN statement correctly. Here's the code:

a = Program
b = language

strSQL = "SELECT TOP 1 userID FROM attendance where attendance.Programs LIKE '*" & a & "*' AND attendance.Language LIKE '*" & b & "*' AND Status = 'Available' AND attendance.Tracking = 0"

Set rs = db.OpenRecordset(strSQL, dbOpenDynaset)

If strSQL = Null Then
    strSQL = "SELECT TOP 1 userID FROM attendance where attendance.Programs LIKE '*" & a & "*' AND Status = 'Available' AND attendance.Tracking = 0"
    Set rs = db.OpenRecordset(strSQL, dbOpenDynaset)
End IF

Thank you :)

8
  • @Bohemian this is my problem statement: However, if there is not a matching value for language then the code continues to just loop. and.. but I can't get it to run through the next strSQL. I think my error is that I am not writing the IF/THEN statement correctly. Commented May 23, 2015 at 21:34
  • 1
    Harsh judgement by Bohemian. Lilly, strSQL will never be null, since your setting it to the SQL string. Check the recordset instead (if it's empty or not). Commented May 23, 2015 at 21:34
  • Hi @Mackan I agree! I was kind of shocked to be honest, but it's all good. I understand what you're saying. Should I check the recordset after the initial strSQL? Commented May 23, 2015 at 21:37
  • rs either contains records or not. So you'll need to check if after Set rs = .... But, and this is probably one of the reasons Bohemian put this on hold, I can't see any loop that you describe. I can't follow your logic, but I can say that the if strSQL = null is not correct. Commented May 23, 2015 at 21:42
  • @Mackan you're right, the loop is at the bottom of this full code. I try not to put full code just because it can be so large and people don't have the time to read the full code. I guess I'll add it for reference. So for the checking after the set rs = ... would something like this: If rs!UserID = Null Then work? Because if the UserID is not set to a value I know there wasn't a language that matched. Commented May 23, 2015 at 21:47

1 Answer 1

1

I think you should change it to

   Set rs = db.OpenRecordset(strSQL, dbOpenDynaset)

If rs.recordcount =0  Then

    strSQL = "SELECT TOP 1 userID FROM attendance where attendance.Programs LIKE '*" & a & "*' AND Status = 'Available' AND attendance.Tracking = 0"
    Set rs = db.OpenRecordset(strSQL, dbOpenDynaset)
End IF
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.