Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old May 26th, 2006, 11:21 AM
Registered User
 
Join Date: Feb 2006
Location: Warrington, , United Kingdom.
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?
Reply With Quote
  #2 (permalink)  
Old May 26th, 2006, 11:26 AM
Friend of Wrox
 
Join Date: Oct 2004
Location: Clinton, UT, USA.
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
Reply With Quote
  #3 (permalink)  
Old May 26th, 2006, 12:47 PM
Friend of Wrox
Points: 9,611, Level: 42
Points: 9,611, Level: 42 Points: 9,611, Level: 42 Points: 9,611, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2004
Location: Washington, DC, USA.
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
Reply With Quote
  #4 (permalink)  
Old May 29th, 2006, 10:51 AM
Authorized User
 
Join Date: May 2006
Location: , , .
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default

try doing this..

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

Reply With Quote
  #5 (permalink)  
Old May 30th, 2006, 06:34 AM
Registered User
 
Join Date: Feb 2006
Location: Warrington, , United Kingdom.
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 !
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 01:17 PM.


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