Passing field name to sub

M

Max Moor

Hi All,
Here is a code snippet..


rstTable.Open "tblPlumbers", CurrentProject.Connection, _
adOpenKeyset, adLockOptimistic, adCmdTableDirect
rstTable.MoveFirst

Do
If (rstTable!idxContact = lIdxContact) Then
rstTable!idxContact = cUndefined
rstTable.UpdateBatch
End If

rstTable.MoveNext

Loop While Not rstTable.EOF

rstTable.Close


I'm searching for the index "lIdxContact" in a number of tables, and,
if found, changing it to "cUndefined". This is to make these references
point to something before deleting the underluying contact.
I have to do this in 5 tables, so want this to be a procedure. I see
that I can pass the name of the table to it as a string. How do I pass in
the reference to the field of the table I'm testing? It's not idxContact
in all of them.Is there a way to pass a field name, such that it can be
used in an "If" like this?
 
D

Dan Artuso

Hi,
Sure, just use this syntax:
If (rstTable(yourVariable) = lIdxContact) Then


Where yourVariable is the Field Name
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top