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 May 26th, 2006, 11:21 AM
Registered User
 
Join Date: Feb 2006
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Paul_Tic
Default Help With SQL Query in VBA

I am running a SQL Append query in VBA and it is working fine. I now want to add a condition where a field value matches a variable value in my code but cannot seem to get it to work. SQL String is as follows

"INSERT INTO tblItemHistory ( UNIQUE_ID, ITEMNO, SELL, COST, DATE_FLD, TYPE, DOC_TYPE, DOC_NO, QTY, QTY_STK, AVG_COST, DB_SERVER_DATE ) SELECT dbo_INVHIST.UNIQUE_ID, dbo_INVHIST.ITEMNO, dbo_INVHIST.SELL, dbo_INVHIST.COST, dbo_INVHIST.DATE_FLD, dbo_INVHIST.TYPE, dbo_INVHIST.DOC_TYPE, dbo_INVHIST.DOC_NO, dbo_INVHIST.QTY, dbo_INVHIST.QTY_STK, dbo_INVHIST.AVG_COST, dbo_INVHIST.DB_SERVER_DATE FROM dbo_INVHIST WHERE (((dbo_INVHIST.ITEMNO)= strItemCode))"

Each time I run it, it is bringing up a parameter box for strItemCode.

Could anyone please help?
 
Old May 26th, 2006, 11:26 AM
Friend of Wrox
 
Join Date: Oct 2004
Posts: 564
Thanks: 0
Thanked 4 Times in 4 Posts
Default

Try and change the last section from ....

Code:
dbo_INVHIST WHERE (((dbo_INVHIST.ITEMNO)= strItemCode))"
to

Code:
dbo_INVHIST WHERE (((dbo_INVHIST.ITEMNO)= '" & strItemCode & "'))"
HTH

Mike


Mike
EchoVue.com
 
Old May 26th, 2006, 12:47 PM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

Unless its a number in which case:

WHERE (((dbo_INVHIST.ITEMNO)= " & strItemCode & "))"

It looks like a string, of course, but I have seen coders name all their varialbles "strXX" if they don't code much or are coding fast (I have done that.)

:D


mmcdonal
 
Old May 29th, 2006, 10:51 AM
Authorized User
 
Join Date: May 2006
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default

try doing this..

WHERE (((dbo_INVHIST.ITEMNO)= " & Me.strItemCode & "));"

 
Old May 30th, 2006, 06:34 AM
Registered User
 
Join Date: Feb 2006
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Paul_Tic
Default

Thanks echovue, that works a treat !





Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA - SQL query returns nothing from MySQL Calligra Access VBA 6 September 19th, 2007 04:10 PM
Long SQL Query (>1024) in VBA??? mlep Excel VBA 1 June 14th, 2007 08:41 PM
SQL Date query in Excel VBA lanewalk Excel VBA 2 September 27th, 2006 02:04 AM
Running an SQL query in VBA... Augusta Access VBA 3 December 1st, 2004 05:17 AM
Excel VBA to SQL & back to VBA edesousa Excel VBA 1 June 1st, 2004 02:39 AM





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