Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Executing SQL code from VB

Status
Not open for further replies.

bhujanga

Programmer
Oct 18, 2007
181
US
I have a series of very similar Append queries (maybe 18) that I want to run when I clcik on a commad button. I'd rather not actually have all of those queries sitting around, so my plan is to convert them to their SQL code and put them all in the VB code.
I tried just pasting the sql code for one of the queries into the VB routine and not surprisingly it wasn't that simple. Is there something you need to preface it with like "Run SQL..." or something?

This happens to be the code that I tried it with:
INSERT INTO [Planning Quantities] ( IML, Item, [Per Unit Quantity], Units, [Run Qty] )
SELECT "I" AS IML, Products.[Ingredient], Products.[Ingredient Qty], Products.[IngQtyUnit], Products.[Planning Batch Quantity]
FROM Products
WHERE (((Products.InActive)=False));

Thanks.
 
Code:
Dim strSQL as String
strSQL = "INSERT INTO [Planning Quantities] " & _
   "(IML, Item, [Per Unit Quantity], Units, [Run Qty] ) " & _
   "SELECT 'I', Ingredient, [Ingredient Qty], [IngQtyUnit], " & _
   "[Planning Batch Quantity] " & _
   "FROM Products " & _
   "WHERE InActive= 0"
Currentdb.Execute strSQL, dbFailOnError

Duane
Hook'D on Access
MS Access MVP
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top