Solved

Need help with syntax with select query

Posted on 2006-06-19
3
222 Views
Last Modified: 2010-04-30
I need help with the syntax with this piece of code:

Src =        SELECT Table1.[AS400 ID], Sum(Table1.LoanAmt) AS SumOfLoanAmt
FROM Table1
WHERE (((Table1.PoolCode)<>"GOVT" And (Table1.PoolCode)<>"G2BD" And (Table1.PoolCode)<>"G21A" And (Table1.PoolCode)<>"G23a" And (Table1.PoolCode)<>"G25A") AND ((Table1.RecDt) Between #6/19/2006# And #6/23/2006#))
GROUP BY Table1.[AS400 ID]
HAVING (((Table1.[AS400 ID])=[forms]![payup table]![AS400 #]));
       
I am using Excel and running Access Select query.    Here is the whole SUB.  

Any help would greatly be appreciated.

////////////////////////////////////////////////
Public Sub OpenADO()
    Dim dbpath As String
    Dim Src As String
    Dim Connection As ADODB.Connection
    Dim Col As Integer
    Dim Recordset As ADODB.Recordset
    Dim As400 As Integer
    Dim A1 As Range
   
   
    'Without Password
    '   dbpath = "Data Source=\\Dtcnas-002mandatory\volume.mdb    
    Set conn = New ADODB.Connection
    With conn
        .Provider = "Microsoft.Jet.OLEDB.4.0"
        .Open dbpath
    End With
   
 '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
   
'   Create RecordSet
    Set Recordset = New ADODB.Recordset
    With Recordset
'       Filter
             
‘This is the piece I need help with
       
Src =        SELECT Table1.[AS400 ID], Sum(Table1.LoanAmt) AS SumOfLoanAmt
FROM Table1
WHERE (((Table1.PoolCode)<>"GOVT" And (Table1.PoolCode)<>"G2BD" And (Table1.PoolCode)<>"G21A" And (Table1.PoolCode)<>"G23a" And (Table1.PoolCode)<>"G25A") AND ((Table1.RecDt) Between #6/19/2006# And #6/23/2006#))
GROUP BY Table1.[AS400 ID]
HAVING (((Table1.[AS400 ID])=[forms]![payup table]![AS400 #]));
       

        .Open source:=Src, ActiveConnection:=conn

'       Write the field names
        For Col = 0 To Recordset.Fields.Count - 1
           Sheet22.Range("r1").Offset(0, Col).Value = Recordset.Fields(Col).Name
        Next

'       Write the recordset
        Sheet22.Range("r2").Offset(0, 0).CopyFromRecordset Recordset
    End With
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
             
   
   
    Set Recordset = Nothing
    conn.Close
    Set conn = Nothing
End Sub
0
Comment
Question by:ca1358
  • 2
3 Comments
 
LVL 65

Accepted Solution

by:
Jim Horn earned 500 total points
ID: 16936561
Src = "SELECT Table1.[AS400 ID], Sum(Table1.LoanAmt) AS SumOfLoanAmt "
Src = Src & "FROM Table1 "
Src = Src & "WHERE Table1.PoolCode NOT IN ('GOVT', 'G2BD', 'G21A', 'G23a', 'G25A') "
Src = Src & "AND Table1.RecDt Between #6/19/2006# And #6/23/2006# "
Src = Src & "GROUP BY Table1.[AS400 ID] "
Src = Src & "HAVING Table1.[AS400 ID]=" & [forms]![payup table]![AS400 #] & ";"
       
0
 

Author Comment

by:ca1358
ID: 16936586
Thank you!!
0
 
LVL 65

Expert Comment

by:Jim Horn
ID: 16936597
Thanks for the grade.  Good luck with your project.  -Jim
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question