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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using a variable for a field name 3

Status
Not open for further replies.

RikHess

MIS
Jul 25, 2002
69
US
I'm sorry if this has been covered before but I don't see it in my archive searches.

I want to use a variable that references a field name in Access VBA. For example, instead of ![FieldName] I'd like to reference something like !strVar to reference the field.

Has someone found a way to do this?

TIA!
 
Hi!

Try this:

Dim strVar As String

strVar = "YourFieldName"
Forms!YourForm.Fields(strVar).etc or
Me.Fields(strVar).etc

Of course strVar can be passed to the function as well.

hth
Jeff Bridgham
bridgham@purdue.edu
 
Thankyou

Jerby, found your post helpful 4 months later.

Here is a star.
 
Jerby, I spoke too soon. What library I need to use me.fields()

when i type me. Fields is not on the list and when i type fields( no options of function appear.

thanks in advance
 
Hi!

Absolutely correct! Sorry for the inconvenience. You have a couple of choices:

1.) Open a recordset that is a clone of the recordsource of the form and you will be able to use the .Fields.

2.) Make sure each field in the recordsource of the form is attached to a text box or combo box etc, even if the control is invisible. Then you can use Me.Controls(etc)

hth
Jeff Bridgham
bridgham@purdue.edu
 
me.Controls(strVar) will work on a form.

Jeremy =============
Jeremy Wallace
Designing, Developing, and Deploying Access Databases Since 1995

Take a look at the Developers' section of the site for some helpful fundamentals.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top