Go Back   Access World Forums > Microsoft Access Discussion > Modules & VBA

 
Reply
 
Thread Tools Rate Thread Display Modes
Old 07-16-2019, 04:33 AM   #1
amir0914
Newly Registered User
 
Join Date: May 2018
Posts: 43
Thanks: 49
Thanked 0 Times in 0 Posts
amir0914 is on a distinguished road
Use variable in select SQL field

Hi all, is it possible to use variable instead of field name after where in select sql ??

pSQL = "select * from tbl_Data WHERE Type1 = '" & Me.Text0.Value & "' "


in the code i want to use variable instead of Type1 and I wrote it but it didn't work :

var = me.text2

pSQL = "select * from tbl_Data WHERE " & var & " = '" & Me.Text0.Value & "' "

amir0914 is offline   Reply With Quote
Old 07-16-2019, 04:41 AM   #2
pbaldy
Wino Moderator
 
pbaldy's Avatar
 
Join Date: Aug 2003
Location: Nevada, USA
Posts: 33,394
Thanks: 13
Thanked 4,124 Times in 4,056 Posts
pbaldy is a splendid one to behold pbaldy is a splendid one to behold pbaldy is a splendid one to behold pbaldy is a splendid one to behold pbaldy is a splendid one to behold pbaldy is a splendid one to behold pbaldy is a splendid one to behold pbaldy is a splendid one to behold
Re: Use variable in select SQL field

Should work. Use this to see how the SQL is coming out:

http://www.baldyweb.com/ImmediateWindow.htm

You may need to add brackets if the field name has spaces or symbols.
__________________
Paul
Microsoft Access MVP 2007-2019

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
pbaldy is offline   Reply With Quote
The Following User Says Thank You to pbaldy For This Useful Post:
amir0914 (07-16-2019)
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Subform Field Linker error: Obj Variable or With block variable not set dmsmythe Reports 2 04-17-2013 07:16 AM
Variable Field name for Select query or split columns DStevens Modules & VBA 4 10-01-2010 12:47 PM
Refer a field using variable name in select statement. aman Modules & VBA 4 09-21-2009 12:53 AM
How to select field from first row where a variable is unticked LWCARAB Modules & VBA 1 05-06-2008 07:02 AM
[SOLVED] Select top [variable] poolieweb Queries 3 07-16-2004 07:45 AM




All times are GMT -8. The time now is 05:26 AM.


Microsoft Access Help
General
Tables
Queries
Forms
Reports
Macros
Modules & VBA
Theory & Practice
Access FAQs
Code Repository
Sample Databases
Video Tutorials

Featured Forum post


Sponsored Links


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
(c) copyright 2017 Access World