Derefrencing fields

  • Thread starter Thread starter CliffordZivi
  • Start date Start date
C

CliffordZivi

I want to access a field in recordset MyRS but the field
changes. As a result, I want to assign a value to a
string variable called "GenericFieldName" and use it's
VALUE to determine which field in the recordset to
access. Something like:

Dim GenericFieldName as String
Forms!frmMail!KeyName = MyRS![GenericFieldName]

So, if the VALUE of GenericFieldName = 'AccountNo' then I
want: Forms!frmMail!CurrentLocationNo = MyRS![AccountNo]
But if the VALUE of GenericFieldName = 'OrderNo' then I
want: Forms!frmMail!CurrentLocationNo = MyRS![OrderNo]

How can this be accomplished?
 
CliffordZivi said:
I want to access a field in recordset MyRS but the field
changes. As a result, I want to assign a value to a
string variable called "GenericFieldName" and use it's
VALUE to determine which field in the recordset to
access. Something like:

Dim GenericFieldName as String
Forms!frmMail!KeyName = MyRS![GenericFieldName]

So, if the VALUE of GenericFieldName = 'AccountNo' then I
want: Forms!frmMail!CurrentLocationNo = MyRS![AccountNo]
But if the VALUE of GenericFieldName = 'OrderNo' then I
want: Forms!frmMail!CurrentLocationNo = MyRS![OrderNo]

How can this be accomplished?
myRs(fieldnameStringvariable) works. So, both expressions above come to

forms!frmMail!currentlocationno = myrs(genericfieldname)
 
You can use syntax like:
Dim strGenericFieldName as String
strGenericFieldName = "AccountNo"
MyRs.Fields(strGenericFieldName)
 
Back
Top