Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access
|
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access 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 June 15th, 2006, 02:37 PM
Registered User
 
Join Date: Jun 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Passing Query from Access to MySAL using VBA

I am looking for some help.

I am using Access as a front end and MySQL 5.0 as a back end.

I have created a query that runs in VBA, this query works fine untill I add a line that uses the Sum(Function) see below.

    strSQL = "SELECT " _
    & "tblInventoryTransactions.IMItemCode, " _
    & "tblInventoryTransactions.RicoeInventory, " _
    & "SUM(tblInventoryTransactions.Received) as sReceived " _
    & "From " _
    & "tblInventoryTransactions " _
    & "Where " _
    & "tblInventoryTransactions.IMItemCode = 'HELP56140902' " _
    & "Group By " _
    & "tblInventoryTransactions.IMItemCode, " _
    & "tblInventoryTransactions.RicoeInventory " _
    & "Order By " _
    & "tblInventoryTransactions.IMItemCode Asc, " _
    & "tblInventoryTransactions.RicoeInventory Asc"

When I do a debug.print I get this "SELECT tblInventoryTransactions.IMItemCode, tblInventoryTransactions.RicoeInventory, SUM(tblInventoryTransactions.Received) as sReceived From tblInventoryTransactions Where tblInventoryTransactions.IMItemCode = 'HELP56140902' Group By tblInventoryTransactions.IMItemCode, tblInventoryTransactions.RicoeInventory Order By tblInventoryTransactions.IMItemCode Asc, tblInventoryTransactions.RicoeInventory Asc"

If I paste this into a Passthrough query it works, if I past it into a Query using Navicat it works, but when I run it from VBA it looks like it is working but no records are returned. If I remove the Sum() it works but I need the Sum.

Any help would be appreciated.

 
Old June 19th, 2006, 07:12 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

I am thinking this might have something to do with Jet supporting ANSI 89, and you using something a little more advanced, like 92. Can you recast the VBA SQL in 89 syntax and see if that works?


mmcdonal
 
Old June 19th, 2006, 01:40 PM
Registered User
 
Join Date: Jun 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by mmcdonal
 I am thinking this might have something to do with Jet supporting ANSI 89, and you using something a little more advanced, like 92. Can you recast the VBA SQL in 89 syntax and see if that works?


mmcdonal
Thanks for your responce but I am sending this as a passthrough Query, so that should bypass Jet and ODBC for that matter.
See Below for code.
Dim cnn As ADODB.Connection
Dim rst_PersonDetails As ADODB.Recordset
Dim strSQL As String
Dim intInventory As Long
Dim strIMItemCode As String

    Set cnn = New ADODB.Connection
    Set rst_PersonDetails = New ADODB.Recordset

    strSQL = "SELECT " _
    & "tblInventoryTransactions.IMItemCode, " _
    & "tblInventoryTransactions.RicoeInventory, " _
    & "SUM(tblInventoryTransactions.Received) as sReceived " _
    & "From " _
    & "tblInventoryTransactions " _
    & "Where " _
    & "tblInventoryTransactions.IMItemCode = 'HELP56140902' " _
    & "Group By " _
    & "tblInventoryTransactions.IMItemCode, " _
    & "tblInventoryTransactions.RicoeInventory " _
    & "Order By " _
    & "tblInventoryTransactions.IMItemCode Asc, " _
    & "tblInventoryTransactions.RicoeInventory Asc"

   cnn.ConnectionString = "DRIVER={MySQL ODBC 3.51 Driver};" _
    & "SERVER=172.20.40.147;" _
    & "DATABASE=Cust_Dev;" _
    & "USER=stephej;" _
    & "PASSWORD=;" _
    & "OPTION=" & 1 + 2 + 8 + 32 + 2048 + 16384 + 524288


    cnn.Open
    rst_PersonDetails.CursorLocation = adUseServer

    Set rst_PersonDetails = cnn.Execute(strSQL, adCmdText)



 
Old June 20th, 2006, 06:56 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

If Jet and Access are out of the equation, it might be time to post at MySQL forum or search their web site for the answer. This would seem to work on, say, an MS SQL server.

Just for drill I did an echo of your finished syntax. How does it look?

SELECT tblInventoryTransactions.IMItemCode, tblInventoryTransactions.RicoeInventory, SUM(tblInventoryTransactions.Received) as sReceived From tblInventoryTransactions Where tblInventoryTransactions.IMItemCode = 'HELP56140902' Group By tblInventoryTransactions.IMItemCode, tblInventoryTransactions.RicoeInventory Order By tblInventoryTransactions.IMItemCode Asc, tblInventoryTransactions.RicoeInventory Asc


mmcdonal





Similar Threads
Thread Thread Starter Forum Replies Last Post
passing a parameter to an Access query! pankaj_daga Access VBA 6 November 16th, 2007 12:26 PM
Access VBA passing to subform ayazhoda Access VBA 1 July 11th, 2007 07:45 AM
Passing parameters to Access query pcassistnw Access 0 March 2nd, 2007 11:07 PM
Passing Multiple Parameters into Access Query rit01 Classic ASP Databases 1 October 26th, 2005 04:00 PM
Passing parameter to Access query eapsokha Classic ASP Databases 2 September 16th, 2004 02:49 AM





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