Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I use the following code to define

Status
Not open for further replies.

Wes1961

Technical User
Aug 21, 2001
72
US
I use the following code to define a recordset:

strSQL = "SELECT Purchase.*, Purchase.COR_NUM FROM Purchase ORDER BY Purchase.COR_NUM;"

Set rst = dbs.OpenRecordset(strSQL)


I now want to access the field Cor_Num in the code, if I use

nNum = rst.fields(0)

it works.

However, I don't want to have to look the field number for each field I want to use. How can I refernce the field directly? I have tried several different formats and I can't seem to get anything to work. Can someone help me with the proper syntax?

Some that I've tried:

nNum = rst![Cor_Num]
nNum = rst.[Cor_Num]
nNum = rst.fields.[Cor_Num]

BTW, I'm using Access '97
 
rst.Fields("Cor_Num").Value
is probably the most "correct" form.

But since the Value property is the "default
property" of the field, that part is often dropped,
giving
rst.Fields("Cor_Num")

And since the Fields Collection is the "default
collection" of the recordset, the Fields part can be
dropped, too, giving
rst("Cor_Num")

The first example you show in your post,
nNum = rst![Cor_Num]
should also work


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top