p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


Go Back   p2p.wrox.com Forums > Microsoft Office > Access and Access VBA > Access VBA
I forgot my password Register Now
Register | FAQ | Members List | Calendar | 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 p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.

Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old May 26th, 2006, 12:21 PM
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?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #2 (permalink)  
Old May 26th, 2006, 12:26 PM
Friend of Wrox
Points: 1,371, Level: 14
Points: 1,371, Level: 14 Points: 1,371, Level: 14 Points: 1,371, Level: 14
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2004
Location: Clinton, UT, USA.
Posts: 564
Thanks: 0
Thanked 0 Times in 0 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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #3 (permalink)  
Old May 26th, 2006, 01:47 PM
Friend of Wrox
Points: 9,516, Level: 42
Points: 9,516, Level: 42 Points: 9,516, Level: 42 Points: 9,516, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2004
Location: Washington, DC, USA.
Posts: 3,060
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #4 (permalink)  
Old May 29th, 2006, 11: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 & "));"

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #5 (permalink)  
Old May 30th, 2006, 07: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 !
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
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

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

Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA - SQL query returns nothing from MySQL Calligra Access VBA 6 September 19th, 2007 05:10 PM
Long SQL Query (>1024) in VBA??? mlep Excel VBA 1 June 14th, 2007 09:41 PM
SQL Date query in Excel VBA lanewalk Excel VBA 2 September 27th, 2006 03: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 03:39 AM



All times are GMT -4. The time now is 08:30 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
© 2008 Wiley Publishing, Inc