Solved

Need help with syntax with select query

Posted on 2006-06-19
3
220 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Need VBS version of Excel date conversion 4 65
Excel - Save a copy of work book 13 83
Add a task in Outlook from access 11 35
VBA Shell can't Find Word document 11 77
Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

867 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now