Syntax problem with [FieldNames]

  • Thread starter Thread starter Isis
  • Start date Start date
I

Isis

I have a form open with data in various fields - I have a
field in a table called "PURL" - I have the value displayed in
a control on the form - I can access the contents of this
field in my VB code using something like;

strFieldContents = [PURL]

If the field contains "D:\MyProg\" then after the assignment
my variable, strFieldContents now contains the same text and
this DOES seem to work. However, if I use this code;

I have another variable called 'Temp' which holds the string
"PURL" - I use this code;

strFieldContents = "[" & Temp & "]"

then strFieldContents contains the string "[PURL] - NOT the
contents of the PURL variable.

What am I doing wrong or can I just not do this in VB ?

Any help much appreciated.

Thanks
 
I have a form open with data in various fields - I have a
field in a table called "PURL" - I have the value displayed in
a control on the form - I can access the contents of this
field in my VB code using something like;

strFieldContents = [PURL]

If the field contains "D:\MyProg\" then after the assignment
my variable, strFieldContents now contains the same text and
this DOES seem to work. However, if I use this code;

I have another variable called 'Temp' which holds the string
"PURL" - I use this code;

strFieldContents = "[" & Temp & "]"

then strFieldContents contains the string "[PURL] - NOT the
contents of the PURL variable.

What am I doing wrong or can I just not do this in VB ?

Your Form does not have "fields" - tables and queries have fields;
Forms have controls. It can be confusing because Access both defaults
to naming the control after the field to which it is bound, and lets
you reference fields directly using the Me!controlname or Me!fieldname
syntax - and, as you are seeing, you can even dispense with Me!.

Try

strFieldContents = Me.Controls(Temp)

to select that member of the form's Controls collection, and extract
its value.

John W. Vinson[MVP]
 
Back
Top