references db fields if
The UK's Number 1 for Microsoft Office Training Add this page to your favourites/bookmarksBookmark page
 
View printable version of pagePrintable version
Plus One Google
Customer: Sign in
Delegate: Sign in
Trainer: Log in

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

replyReply Tue 8 Mar 2011, 12:51Delegate Simon said...

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.

For upcoming training course dates see: Pricing & availability

replyReply Tue 8 Mar 2011, 14:37Delegate Simon said...

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.

 

Please browse our web site to find out more about
access course and other Microsoft training courses.

Access tip:

Create own ribbon tab - Access 2010

a. In Access click on the File tab
b. Select Options from left hand side
c. Choose the Customize Ribbon section
d. Click the New Tab button (below the list of tabs on the right hand side of the dialog box)
e. Select the New Tab (Custom) and enter a name, by clicking the Rename button (below the list of tabs on the right hand side of the dialog box)
f. Select the New Group (Custom) and enter a name, by clicking the Rename button (below the list of tabs on the right hand side of the dialog box)
g. Add commands to your tab and group by locating them on the list on the right hand side (remembering that you can change the list using the drop down box at the top of the list of commands) and clicking the Add button between the two panes to add them to your tab and group
h. You can rearrange the commands in your group, the groups on any tab or the tabs, using the up and down arrow buttons beside the list of tabs.
i. Click OK to apply your changes

View all Access hints and tips


Microsoft Certified Partner Accredited Training Provider: Institute of IT Training Institute of Leadership and Management - Certified Courses Security Seal verified by visa, mastercard securecard