Skip to content

Referencing Query Fields

How to reference specific fields in an Access query.

Q:  Lee Aldrich wants to know how to reference specific fields in an Access query/dataset.

 

A:  In VBA code, you can set up a DAO recordset to work with Access data, using the following syntax (the example sets two variables with values picked up from the first row of a table):

 

Dim dbs As DAO.Database

Dim rst As DAO.Recordset

 

Set dbs = CurrentDb

Set rst = dbs.OpenRecordset(“tblInfo”, dbOpenTable)

 

With rst

   .MoveFirst

   strTemplatePath = ![TemplatePath]

   strDownloadPath = ![DownloadPath]

   .Close

End With

Substitute your table (or query) and field names.  If using a query, the OpenRecordset argument would be dbOpenDynaset instead of dbOpenTable.

You also need to specify the row in the query (or table) that you want to use.  This can be done using the .FindFirst method in a recordset, or by using criteria in a query.

About this author

Office 2024 - all you need to know. Facts & prices for the new Microsoft Office. Do you need it?

Microsoft Office upcoming support end date checklist.