A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » General Discussion
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

FieldName Variable in VBA



 
 
Thread Tools Display Modes
  #1  
Old June 1st, 2010, 11:48 PM posted to microsoft.public.access
denyoung
external usenet poster
 
Posts: 21
Default FieldName Variable in VBA

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

--
Dennis
  #2  
Old June 2nd, 2010, 12:03 AM posted to microsoft.public.access
Jeff Boyce
external usenet poster
 
Posts: 8,621
Default FieldName Variable in VBA

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.

"denyoung" wrote in message
...
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

--
Dennis



 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 06:01 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.