Wrox Programmer Forums
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 29th, 2012, 05:04 PM
Registered User
 
Join Date: Mar 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default docmd.runsql

HI I am rather new to access VBA.

i would like to use a variable in a sql statement ie

dim val1 as string
dim strsq1 as string

val1 = "test"

strsql = "select * from table1 where col1 = val1 into test1"

docmd.runsq strsql

but am having issues with the syntax

any help is appreciated

thanks
 
Old March 30th, 2012, 12:58 PM
JP JP is offline
Authorized User
 
Join Date: Apr 2008
Posts: 57
Thanks: 1
Thanked 3 Times in 3 Posts
Default

To get the value of a variable into your SQL statement you would write it like this:

Code:
 
strsql = "select * from table1 where col1 = '" & val1 & "' into test1"
Also I believe it is "docmd.runsql" not "docmd.runsq"
__________________
Regards,
JP
JP SoftTech





Similar Threads
Thread Thread Starter Forum Replies Last Post
Docmd.RunSQL bsharma2011 BOOK: Beginning Access 2003 VBA 0 October 18th, 2011 01:22 PM
Docmd.RunSql Jasonhwrd Access VBA 11 January 6th, 2011 01:02 AM
Docmd.RunSQL Armand elia BOOK: Access 2003 VBA Programmer's Reference 0 June 17th, 2009 03:47 PM
Docmd.runsql anne.burrows VB How-To 2 October 25th, 2006 08:21 AM
Help with DoCmd.RunSQL command ricmar Access VBA 3 July 21st, 2004 03:32 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.