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

references db fields if

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

ResolvedVersion 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:

Space marks

It is good practice not i to have space marks for field names as this can lead to problems when using queries or VBA code. It is much better to use an underscore charcter to represent spaces in field names

View all Access hints and tips

Connect with us:

0207 987 3777

Call for assistance

Request Callback

We will call you back

Server loaded in 0.11 secs.