FieldName Variable in VBA

D

denyoung

Working in Access VBA:


‘Where S1Speech is a field name in an Access 2007 table called SP
‘This 1st example works fine putting the value from S1Speech into the
variable S1

Dim S1 as String
S1= [S1Speech]


‘ These other 2 examples don’t work
Example #2
Dim S1 as String
Dim TXHolder as String
TXHolder = S1Speech
S1=[TXHolder]


Example #3
Dim S1 as String
Dim TXHolder as String
TXHolder = [S1Speech]
S1=TXHolder



Is there a way to use a variable in a situation like this?
Thanks
 
J

Jeff Boyce

Dennis

You don't mention where this code is running.

It would typically be used as code-behind-form, so your use of [S1Speech] is
probably pointing at the FORM, not the table.

If you need to peek into the table to get values, take a look at the
DLookup() function.

If you want to use code-behind-form, the field will need to be available in
the form.

Good luck!

Regards

Jeff Boyce
Microsoft Access MVP

--
Disclaimer: This author may have received products and services mentioned
in this post. Mention and/or description of a product or service herein
does not constitute endorsement thereof.

Any code or pseudocode included in this post is offered "as is", with no
guarantee as to suitability.

You can thank the FTC of the USA for making this disclaimer
possible/necessary.
 

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