references db fields if

Public Schedule Face-to-Face & Online Instructor-Led Training - View dates & book

Forum home » Delegate support and help forum » Microsoft Access VBA Training and help » References to DB fields in If statement not working

References to DB fields in If statement not working

resolvedResolved · Medium Priority · Version 2003

Simon has attended:
No courses

References to DB fields in If statement not working

I've got the following code in a module that deletes data. I've stepped through this and even when both parts of the IF are true the code steps over the delete statement (jumping straight to the endif).

With rstDBTarget
.MoveFirst
Do While Not .EOF
If .Fields("VolID") = iVolID AND _
.Fields("ReqID") = Me.ReqID Then
Debug.Print "Deleted one"
.Delete
.Update
End If
End If
.MoveNext
Loop
End With

Is there a problem with referring directly to the rst fields in the IF clause?

Thanks.

RE: References to DB fields in If statement not working

Ah! Found the problem. iVolID was populated from a list field and, in spite of declared data type, was a string not an integer. Once I coerced the data using Clng it worked.

 

Training courses

 

Training information:

Welcome. Please choose your application (eg. Excel) and then post your question.

Our Microsoft Qualified trainers will then respond within 24 hours (working days).

Frequently Asked Questions
What does 'Resolved' mean?

Any suggestions, questions or comments? Please post in the Improve the forum thread.


 

Access tip:

Combo box for finding records

You can use a combo box in a form to look up a record. If you place the comb box in the Form header, by then selcting they a field type from the drop down loist, you will see the record for it

View all Access hints and tips


Server loaded in 0.07 secs.