Derefrencing fields

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?
 
B

Bas Cost Budde

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)
 
D

Duane Hookom

You can use syntax like:
Dim strGenericFieldName as String
strGenericFieldName = "AccountNo"
MyRs.Fields(strGenericFieldName)
 

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