Results 1 to 2 of 2
  1. #1
    ruthib4 is offline Novice
    Windows XP Access 2003
    Join Date
    Aug 2011
    Posts
    29

    Angry VBA SQL in Access 2010 problem

    Hi everyone,
    Hope all are ok.
    I need your help with the following code, I know that the query results give me 11 records, but when i run it, i got only one, the first one.
    Thanks in advance

    Option Compare Database
    Option Explicit
    Dim FirstDate, SecondDate As String

    Private Sub CmbReportDate_Click()
    If Year(CDate(Me.Cmbreportdate)) = 2011 Then
    QueryActuals
    End If
    End Sub

    Private Sub QueryActuals()
    Dim db As Database
    Dim rst As Recordset
    Dim strQuery As String
    Dim Temp As Variant
    Dim N As Long

    FirstDate = Format(DateAdd("m", -11, CDate(Me.Cmbreportdate)), "mm/dd/yyyy")
    SecondDate = Me.Cmbreportdate

    strQuery = "SELECT [Cards]!country, Sum(TCcountries![Average Exchange]*[Cards]![Actual OK]/-1000000) AS [Actual OK TC],"
    strQuery = strQuery & " Sum(TCcountries![Average Exchange]*[Cards]![Budget OK]/-1000000) AS [Bdgt OK TC]"
    strQuery = strQuery & " FROM [Cards] INNER JOIN TCcountries ON [Cards].country = TCcountries.[Exchange Country]"
    strQuery = strQuery & " WHERE ((([Cards].Description)=""fraudorex"")"


    strQuery = strQuery & " AND (([Cards].DateTC) between #" & FirstDate & "# And #" & SecondDate & "#)"
    strQuery = strQuery & " AND (([Cards].concept)= ""ecr"" Or ([Cards].concept)= ""edb""))"
    strQuery = strQuery & " GROUP BY [Cards].country;"
    Set rst = CurrentDb.OpenRecordset(strQuery, dbOpenDynaset)
    Temp = rst.GetRows

    With rst
    If Not .EOF Then
    Do Until .EOF
    Debug.Print Temp(1, N), Temp(2, N)
    .MoveNext
    Loop
    End If
    End With
    rst.Close
    Set rst = Nothing
    End Sub

  2. #2
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,523
    Presuming the SQL is correct

    http://www.baldyweb.com/ImmediateWindow.htm

    Try this debug line instead of yours

    Debug.Print !FirstFieldName & ", " & !SecondFieldName

    In other words use the recordset.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 6
    Last Post: 02-18-2012, 07:20 AM
  2. Help access 2010 to 2003 vba and sql problem!
    By bcox9 in forum Programming
    Replies: 4
    Last Post: 12-21-2011, 09:42 PM
  3. Access 2010 Database Problem
    By RayMilhon in forum Access
    Replies: 5
    Last Post: 11-28-2011, 03:04 PM
  4. Access 2010 Problem
    By DSTR3 in forum Access
    Replies: 7
    Last Post: 11-29-2010, 05:11 PM
  5. Just got Access 2010-run application problem
    By lycialive in forum Forms
    Replies: 0
    Last Post: 07-09-2010, 08:17 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums