Referencing Field Names

  • Thread starter Thread starter Rhonda
  • Start date Start date
R

Rhonda

Hi,

I need to be able to reference a field name by using a
variable. I need to check whether or not the value of the
field itself is true, but the name of the field will
change depending where in the code I am referencing it.
Do I set a string variable? If so, how do I get my code
to recognize it as a field name and not just a string.

Any help is appreciated,
Rhonda...
 
rhonda,

if i understand your question properly, study this for the answer.

hope it helps.

fred rosenberg

'============================
Public Sub PrintFieldName(strTableName As String, strFieldName As String)

Dim dbs As Database
Dim rst As Recordset
Dim tdf As TableDef

On Error GoTo Err_PrintFieldName

Set dbs = CurrentDb()
Set tdf = dbs.TableDefs(strTableName)
Set rst = tdf.OpenRecordset

While Not rst.EOF
Debug.Print rst.Fields(strFieldName)
rst.MoveNext
Wend

rst.close

Exit_PrintFieldName:

On Error Resume Next
Set dbs = Nothing
Set rst = Nothing
Set tdf = Nothing
Exit Sub

Err_PrintFieldName:

MsgBox Err & ":" & Error$, vbCritical, "Module1" & ": " & "PrintFieldName"
Resume Exit_PrintFieldName

End Sub
 
Field in a Record? Control on a Form? Field is often used interchangeably.
If the former, what is the context... in an Action Query, Select Query, code
behind a form, code in a standare module? If the latter, from code behind
the form or code in a standard module, or in the Criteria section of the
Query Builder?

For a Field in a Recordset opened as "rs",

Dim strVarName as String

strVarName = "CustomerID"
rs(strVarName) = <whatever>

Larry Linson
Microsoft Access MVP
 
Back
Top