|
|
 |
| 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.
|
 |

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
|
|
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?
|

May 26th, 2006, 12:26 PM
|
|
Friend of Wrox
|
|
Join Date: Oct 2004
Location: Clinton, UT, USA.
Posts: 564
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|

May 26th, 2006, 01:47 PM
|
|
Friend of Wrox
|
|
Join Date: Mar 2004
Location: Washington, DC, USA.
Posts: 3,060
Thanks: 0
Thanked 10 Times in 10 Posts
|
|
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
|

May 29th, 2006, 11:51 AM
|
|
Authorized User
|
|
Join Date: May 2006
Location: , , .
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
try doing this..
WHERE (((dbo_INVHIST.ITEMNO)= " & Me.strItemCode & "));"
|

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
|
|
Thanks echovue, that works a treat !
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
 |