Field name parameter

G

Gwen Powell

I am trying to write a simple piece of code that I will use over and over
again. I need to pass a field name as well as the table names to the code
but I cannot seem to get the syntax correct when trying to pass the field
name.

I have something like:
NumberThis(T1, T2, F1) 'F1 is the field name
Dim myTable, mySeed, myDB, myField
Set myDB=CurrentDB()
Set myTable=myDB.Openrecordset(T1)
Set mySeed=myDB.Openrecordset(T2)
Set myField=myTable.F1 '''This is where the problem is--I cannot remember
nor find the proper syntax
etc, etc

Thanks for any help.
Gwen Powell
Torrance Unified School District
 
K

Ken Snell [MVP]

Try this (assumes you're passing a string to the code where the string is
the name of the field):

Set myField=myTable.Fields("F1")
 
D

Duane Hookom

If F1 is a string variable containing a field name then I think this should
be:
Set myField=myTable.Fields(F1)
 

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