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

    Formatting dates problem

    Hi Everyone,


    I have a problem with one vba code i am working on, I need to use two dates to obtain information from a query, my regional date format is "dd/mm/yyyy" and i need my project to be open in another country with the format "yyyy/mm/dd" or any other country. I used (below) Allen Brown solution but i does not seem to be working:
    Function SQLDate(varDate As Variant) As String 'Purpose: Return a delimited string in the date format used natively by JET SQL. 'Argument: A date/time value. 'Note: Returns just the date format if the argument has no time component, ' or a date/time format if it does. 'Author: Allen Browne. allen@allenbrowne.com, June 2006. If IsDate(varDate) Then If DateValue(varDate) = varDate Then SQLDate = Format$(varDate, "\#mm\/dd\/yyyy\#") Else SQLDate = Format$(varDate, "\#mm\/dd\/yyyy hh\:nn\:ss\#") End If End If End Function

    My project works perfectly when i use it with my regional date settings but when i change to a different format i got the error "Either BOF or EOF is true, or the current record has been deleted. Requested operation requires a current record"
    The code looks like this so far:

    Private Sub summary()
    Dim Rst As ADODB.Recordset
    Dim cn As ADODB.Connection
    Dim strQuery As String
    Dim Temp As Variant
    Dim N As Long
    Dim m As Integer

    Fecha3=SqlDate(reportdate1)
    fechadesde=SqlDate1(reportdate2)

    Set Rst = New ADODB.Recordset
    strQuery = "SELECT [itaca cards]!país, Sum(TCpaises![Cambio Medio]*[Itaca Cards]![Real OK]/-1000000) AS [Real OK TC], Sum(TCpaises![Cambio Medio]*[Itaca Cards]![Presupuestado OK]/-1000000) AS [Presup OK TC] " & vbCrLf & _
    "FROM [Itaca Cards] INNER JOIN TCpaises ON [Itaca Cards].País = TCpaises.[País Tipo de Cambio] " & vbCrLf & _
    "WHERE ((([Itaca Cards].Descripción)=""orex fraude"") AND (([Itaca Cards].Fecha) between " & FechaDesde & " And " & Fecha3 & ") AND (([Itaca Cards].Negocio)=""ecr"" Or ([Itaca Cards].Negocio)=""edb"")) " & vbCrLf & _
    "GROUP BY [Itaca Cards].País;"
    Rst.Open strQuery, CurrentProject.Connection, adOpenStatic, adLockOptimistic
    Temp = Rst.GetRows
    With Me
    .ar1 = Temp(1, N)
    .ar2 = Temp(2, N)
    .br1 = Temp(1, N + 1)
    .br2 = Temp(2, N + 1)
    .ch1 = Temp(1, N + 2)
    .ch2 = Temp(2, N + 2)
    .co1 = Temp(1, N + 3)
    .co2 = Temp(2, N + 3)
    .es1 = Temp(1, N + 4)
    .es2 = Temp(2, N + 4)
    .us1 = Temp(1, N + 5)
    .us2 = Temp(2, N + 5)
    .me1 = Temp(1, N + 6)
    .me2 = Temp(2, N + 6)
    .po1 = Temp(1, N + 8)
    .po2 = Temp(2, N + 8)
    .pol1 = Temp(1, N + 7)
    .pol2 = Temp(2, N + 7)
    .pu1 = Temp(1, N + 9)
    .pu2 = Temp(2, N + 9)
    .uk1 = Temp(1, N + 10)
    .uk2 = Temp(2, N + 10)
    End With

    Rst.Close
    Set Rst = Nothing
    end sub

    What Am I doing wrong?. Any help would be really appreciated.

    Cheers

  2. #2
    ssanfu is offline Master of Nothing
    Windows 2K Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Things I see:

    Are the top two lines in every module:
    Option Compare Database
    Option Explicit


    Are "Fecha3" and "fechadesde" variables in code or controls on a form? They are not declared (DIM) in the code.

    Do not use "vbcrlf" when creating your query

    For ease of reading, this is how I format my SQL strings:
    Code:
    strQuery = "SELECT [itaca cards]!país, Sum(TCpaises![Cambio Medio]*[Itaca Cards]![Real OK]/-1000000) AS [Real OK TC],"
    strQuery = strQuery & " Sum(TCpaises![Cambio Medio]*[Itaca Cards]![Presupuestado OK]/-1000000) AS [Presup OK TC]"
    strQuery = strQuery & " FROM [Itaca Cards] INNER JOIN TCpaises ON [Itaca Cards].País = TCpaises.[País Tipo de Cambio]"
    strQuery = strQuery & " WHERE ((([Itaca Cards].Descripción)=""orex fraude"")"
    strQuery = strQuery & " AND (([Itaca Cards].Fecha) between " & FechaDesde & " And " & Fecha3 & ")"
    strQuery = strQuery & " AND (([Itaca Cards].Negocio)= ""ecr"" Or ([Itaca Cards].Negocio)= ""edb""))"
    strQuery = strQuery & " GROUP BY [Itaca Cards].País;"
    What does the strQuery look like? (is it properly constructed?) Add Debug.Print strQuery or Msgbox strQuery before Rst.Open

    In this piece of code,

    Fecha3=SqlDate(reportdate1)
    fechadesde=SqlDate1(reportdate2)

    the values in reportdate1 and reportdate2 *must* look like:
    #2012/2/1#
    #2012/02/01#
    #2/1/2012#
    #02/01/2012#

    (delimited by hash marks "#")

  3. #3
    ruthib4 is offline Novice
    Windows XP Access 2003
    Join Date
    Aug 2011
    Posts
    29
    Thank very much SSANFU,
    Below and on each of your comments you will find the my answers:

    Quote Originally Posted by ssanfu View Post
    Things I see:

    Are the top two lines in every module: Yes both are in every module
    Option Compare Database
    Option Explicit


    Are "Fecha3" and "fechadesde" variables in code or controls on a form? They are not declared (DIM) in the code.
    Both "Fecha3" and "fechadesde" are not variables, they are combo box controls used in my form.

    Do not use "vbcrlf" when creating your query.
    This is a very good idea, definitely i will be using it, it is much more easier to read and to audit.

    For ease of reading, this is how I format my SQL strings:
    Code:
    strQuery = "SELECT [itaca cards]!país, Sum(TCpaises![Cambio Medio]*[Itaca Cards]![Real OK]/-1000000) AS [Real OK TC],"
    strQuery = strQuery & " Sum(TCpaises![Cambio Medio]*[Itaca Cards]![Presupuestado OK]/-1000000) AS [Presup OK TC]"
    strQuery = strQuery & " FROM [Itaca Cards] INNER JOIN TCpaises ON [Itaca Cards].País = TCpaises.[País Tipo de Cambio]"
    strQuery = strQuery & " WHERE ((([Itaca Cards].Descripción)=""orex fraude"")"
    strQuery = strQuery & " AND (([Itaca Cards].Fecha) between " & FechaDesde & " And " & Fecha3 & ")"
    strQuery = strQuery & " AND (([Itaca Cards].Negocio)= ""ecr"" Or ([Itaca Cards].Negocio)= ""edb""))"
    strQuery = strQuery & " GROUP BY [Itaca Cards].País;"
    What does the strQuery look like? (is it properly constructed?) Add Debug.Print strQuery or Msgbox strQuery before Rst.Open

    The query works perfectly when i am using my local regional settings (dd/mm/yyyy), here are the debug.print results:

    1,24462033653648 0,83558437632
    59,297205970696 31,3194676971513
    1,14233247658332 0,35292829291632
    0,1878249487044 0,27306606672856
    2,6882 2,9484
    3,86557904596481 2,5108960695173
    7,56387079941248 7,54875972810176
    5,18277049995445E-02 0,011794182931632
    0,3746 0,8169
    0,55404404485512 0,64855447909368
    16,1053447637142 15,9613213350303


    In this piece of code,

    Fecha3=SqlDate(reportdate1)
    fechadesde=SqlDate1(reportdate2)

    But when i change my pc to, lets say, Poland date settings ("yyyy-mm-dd") i got the error "BOF or EOF is true..... etc" for this i use the following function from Allen Brown:

    Code:
    Function SQLDate(varDate As Variant) As String       'Author:     Allen Browne. 
      If IsDate(varDate) Then         
         If DateValue(varDate) = varDate Then
             SQLDate = Format$(varDate, "\#mm\/dd\/yyyy\#")
         Else
            SQLDate = Format$(varDate, "\#mm\/dd\/yyyy hh\:nn\:ss\#")
         End If     
    End If   
    End Function


    And what i am getting is "#12/31/2012#".



    the values in reportdate1 and reportdate2 *must* look like:
    #2012/2/1#
    #2012/02/01#
    #2/1/2012#
    #02/01/2012#

    (delimited by hash marks "#")

  4. #4
    ssanfu is offline Master of Nothing
    Windows 2K Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    What I meant was to add the Debug.Print like this:

    Code:
    strQuery = "SELECT [itaca cards]!país, Sum(TCpaises![Cambio Medio]*[Itaca Cards]![Real OK]/-1000000) AS [Real OK TC],"
    strQuery = strQuery & " Sum(TCpaises![Cambio Medio]*[Itaca Cards]![Presupuestado OK]/-1000000) AS [Presup OK TC]"
    strQuery = strQuery & " FROM [Itaca Cards] INNER JOIN TCpaises ON [Itaca Cards].País = TCpaises.[País Tipo de Cambio]"
    strQuery = strQuery & " WHERE ((([Itaca Cards].Descripción)=""orex fraude"")"
    strQuery = strQuery & " AND (([Itaca Cards].Fecha) between " & FechaDesde & " And " & Fecha3 & ")"
    strQuery = strQuery & " AND (([Itaca Cards].Negocio)= ""ecr"" Or ([Itaca Cards].Negocio)= ""edb""))"
    strQuery = strQuery & " GROUP BY [Itaca Cards].País;"
    
    Debug.Print strQuery
    
    Rst.Open
    Then set a breakpoint on the Rst.Open line. Open the immediate window, copy the SQL line and post it. I'm interested in what the dates look like.

    You can go to the database window, create a new query, switch to SQL view, paste in the line and execute it.

    Have you seen this page by Allen Browne? Maybe it will help:

    International Dates in Access
    http://allenbrowne.com/ser-36.html

    Also here

    http://www.trigeminal.com/lang/1033/...asp?ItemID=7#7

  5. #5
    ruthib4 is offline Novice
    Windows XP Access 2003
    Join Date
    Aug 2011
    Posts
    29
    Hi SSANFU,

    Here is the debug.print of the SQL, in regards to Allen Brown's I did see it and i am using it, if your see my previous post the SQLdate rutine is his, the dates are converted to what you are seeing in the debug.printed SQL below.

    Code:
    SELECT [itaca cards]!país, Sum(TCpaises![Cambio Medio]*[Itaca Cards]![Real OK]/-1000000) AS [Real OK TC], Sum(TCpaises![Cambio Medio]*[Itaca Cards]![Presupuestado OK]/-1000000) AS [Presup OK TC] FROM [Itaca Cards] INNER JOIN TCpaises ON [Itaca Cards].País = TCpaises.[País Tipo de Cambio] WHERE ((([Itaca Cards].Descripción)="orex fraude") AND (([Itaca Cards].Fecha) between #01/01/2011# And #12/01/2011#) AND (([Itaca Cards].Negocio)= "ecr" Or ([Itaca Cards].Negocio)= "edb")) GROUP BY [Itaca Cards].País;
    .

    The regional settings i used are Poland "yyyy-mm-dd" and still getting error 3021: BOF or EOF is true......


    Thanks again

    Quote Originally Posted by ssanfu View Post
    What I meant was to add the Debug.Print like this:

    Code:
    strQuery = "SELECT [itaca cards]!país, Sum(TCpaises![Cambio Medio]*[Itaca Cards]![Real OK]/-1000000) AS [Real OK TC],"
    strQuery = strQuery & " Sum(TCpaises![Cambio Medio]*[Itaca Cards]![Presupuestado OK]/-1000000) AS [Presup OK TC]"
    strQuery = strQuery & " FROM [Itaca Cards] INNER JOIN TCpaises ON [Itaca Cards].País = TCpaises.[País Tipo de Cambio]"
    strQuery = strQuery & " WHERE ((([Itaca Cards].Descripción)=""orex fraude"")"
    strQuery = strQuery & " AND (([Itaca Cards].Fecha) between " & FechaDesde & " And " & Fecha3 & ")"
    strQuery = strQuery & " AND (([Itaca Cards].Negocio)= ""ecr"" Or ([Itaca Cards].Negocio)= ""edb""))"
    strQuery = strQuery & " GROUP BY [Itaca Cards].País;"
    
    Debug.Print strQuery
    
    Rst.Open
    Then set a breakpoint on the Rst.Open line. Open the immediate window, copy the SQL line and post it. I'm interested in what the dates look like.

    You can go to the database window, create a new query, switch to SQL view, paste in the line and execute it.

    Have you seen this page by Allen Browne? Maybe it will help:

    International Dates in Access
    http://allenbrowne.com/ser-36.html

    Also here

    http://www.trigeminal.com/lang/1033/...asp?ItemID=7#7

  6. #6
    ssanfu is offline Master of Nothing
    Windows 2K Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    The SQL for the debug line looks correct. I cannot reproduce the error even when I changed my regional settings to Polish. I must not have the tables set up the same as you.

    Try this:
    in the database window, create a new query, switch to SQL view and paste in:

    Code:
    SELECT [itaca cards]!país FROM [Itaca Cards] WHERE [Itaca Cards].Fecha) between #01/01/2011# And #12/01/2011#
    If that returns records, then try:
    Code:
    SELECT [itaca cards]!país FROM [Itaca Cards] WHERE ((([Itaca Cards].Descripción)="orex fraude") AND (([Itaca Cards].Fecha) between #01/01/2011# And #12/01/2011#) AND  (([Itaca Cards].Negocio)= "ecr" Or ([Itaca Cards].Negocio)= "edb"))
    Results???

  7. #7
    ruthib4 is offline Novice
    Windows XP Access 2003
    Join Date
    Aug 2011
    Posts
    29
    On the first code I got results like this:

    Expr1
    Argentina
    Argentina
    Argentina
    Argentina
    Argentina
    Argentina
    Argentina
    Argentina
    Argentina
    Argentina
    Argentina
    Argentina
    Argentina
    Argentina
    Argentina
    Argentina
    Argentina
    Argentina
    Argentina
    Argentina
    Argentina
    Argentina
    Argentina
    Argentina
    Chile
    Chile
    Chile
    Chile
    Chile
    Chile
    Chile
    Chile
    Chile

    on the second code I am getting results as well as follows:
    Expr1
    Argentina
    Argentina
    Argentina
    Argentina
    Argentina
    Argentina
    Argentina
    Argentina
    Argentina
    Argentina
    Argentina
    Argentina
    Argentina
    Argentina
    Argentina
    Argentina
    Argentina
    Argentina
    Argentina
    Argentina
    Argentina
    Argentina
    Argentina
    Argentina
    Chile
    Chile
    Chile
    Chile
    Chile
    Chile
    Chile
    Chile
    Chile
    Chile
    Chile
    Chile
    Chile
    Chile
    Chile
    Chile
    Chile
    Chile
    Chile
    Chile
    Chile
    Chile
    Chile
    Chile
    Chile
    Chile
    Chile
    Chile
    Chile
    Chile
    Chile
    Chile
    Chile
    Chile
    Chile
    Chile
    Chile
    Chile
    Chile
    Chile
    Chile
    Chile
    Chile
    Chile
    Chile
    Chile
    Chile
    Chile
    Colombia
    Colombia
    Colombia
    Colombia
    Colombia
    Colombia
    Colombia
    Colombia
    Colombia
    Colombia
    Colombia
    Colombia
    Colombia
    Colombia
    Colombia
    Colombia
    Colombia
    Colombia
    Colombia
    Colombia
    Colombia
    Colombia
    Colombia
    Colombia
    México
    México
    México
    México
    México
    México
    México
    México
    México
    México
    México
    México
    México
    México
    México
    México
    México
    México
    México
    México
    México
    México
    México
    México
    Puerto Rico
    Puerto Rico
    Puerto Rico
    Puerto Rico
    Puerto Rico
    Puerto Rico
    Puerto Rico
    Puerto Rico
    Puerto Rico
    Puerto Rico
    Puerto Rico
    Puerto Rico
    Puerto Rico
    Puerto Rico
    Puerto Rico
    Puerto Rico
    Puerto Rico
    Puerto Rico
    Puerto Rico
    Puerto Rico
    Puerto Rico
    Puerto Rico
    Puerto Rico
    Puerto Rico
    Brasil
    Brasil
    Brasil
    Brasil
    Brasil
    Brasil

  8. #8
    ssanfu is offline Master of Nothing
    Windows 2K Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    So the other two queries returned records. Try this query:
    Code:
    strQuery = "SELECT [itaca cards]![país], [TCpaises]![País Tipo de Cambio], [Itaca Cards]![Presupuestado OK],"
    strQuery = strQuery & " [Itaca Cards]![Real OK], [TCpaises]![Cambio Medio], [Itaca Cards]![Fecha]"
    strQuery = strQuery & " FROM [Itaca Cards] INNER JOIN TCpaises ON [Itaca Cards].País = TCpaises.[País Tipo de Cambio]"
    strQuery = strQuery & " GROUP BY [Itaca Cards]![País];"

  9. #9
    ruthib4 is offline Novice
    Windows XP Access 2003
    Join Date
    Aug 2011
    Posts
    29
    Hi SSANFU,

    once i run your code i got the following error,
    Error -2147217887 (80040e21)
    YOu have attempted to runa query that does not inlcude the expresion 'TCpaises]![País tipo de cambio' as part of the function


    Thanks again for your time here.

    Regards





    Quote Originally Posted by ssanfu View Post
    So the other two queries returned records. Try this query:
    Code:
    strQuery = "SELECT [itaca cards]![país], [TCpaises]![País Tipo de Cambio], [Itaca Cards]![Presupuestado OK],"
    strQuery = strQuery & " [Itaca Cards]![Real OK], [TCpaises]![Cambio Medio], [Itaca Cards]![Fecha]"
    strQuery = strQuery & " FROM [Itaca Cards] INNER JOIN TCpaises ON [Itaca Cards].País = TCpaises.[País Tipo de Cambio]"
    strQuery = strQuery & " GROUP BY [Itaca Cards]![País];"

  10. #10
    ssanfu is offline Master of Nothing
    Windows 2K Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Sorry... I meant to take out the "GROUP BY" clause. That is for totals queries.
    Try this:
    Code:
    strQuery = "SELECT [itaca cards]![país], [TCpaises]![País Tipo de Cambio], [Itaca Cards]![Presupuestado OK]," 
    strQuery = strQuery & " [Itaca Cards]![Real OK], [TCpaises]![Cambio Medio], [Itaca Cards]![Fecha]" 
    strQuery = strQuery & " FROM [Itaca Cards] INNER JOIN TCpaises ON [Itaca Cards].País = TCpaises.[País Tipo de Cambio];"
    Are records returned?

  11. #11
    ruthib4 is offline Novice
    Windows XP Access 2003
    Join Date
    Aug 2011
    Posts
    29
    With This one I do get records as follows:

    Argentina 0
    Argentina 0
    Argentina 0
    Argentina 0
    Argentina 0
    Argentina 0
    Argentina 0
    Argentina 0
    Argentina 0
    Argentina 0
    Argentina 0
    Argentina 0
    Argentina 0
    Argentina 0
    Argentina 0
    Argentina 0
    Argentina 0
    Argentina 0
    Argentina 0
    Argentina 0
    Argentina 0
    Argentina 0
    Argentina 0
    Argentina 0
    Argentina 0
    Argentina 0
    Argentina 0
    Argentina 0
    Argentina 0
    Argentina 0
    Argentina 0
    Argentina 0
    Argentina 0
    Argentina 0
    Argentina 0
    Argentina 0
    Argentina 0
    Argentina 0
    Argentina 0
    Argentina 0
    Argentina 0
    Argentina 0
    Argentina 0
    Argentina 0
    Argentina 0
    Argentina 0
    Argentina 0 Argentina 0
    Argentina 0
    Argentina 0
    Argentina 0
    Argentina 0
    Argentina 0
    Argentina 0
    Argentina 0
    Argentina 0
    Argentina 0
    Argentina 0
    Argentina 0
    Argentina 0
    Argentina 0
    Chile -86772411,294
    Chile 38263410,36
    Chile 66209277,536
    Chile 161091181,532
    Chile 30066085,7067
    Chile 35258269,51
    Chile -56238227,7661
    Chile -70653768,3208
    Chile -10520563,2162
    Chile -5089100
    Chile -9714100
    Chile -8444100
    Chile 0
    Chile 0


    Quote Originally Posted by ssanfu View Post
    Sorry... I meant to take out the "GROUP BY" clause. That is for totals queries.
    Try this:
    Code:
    strQuery = "SELECT [itaca cards]![país], [TCpaises]![País Tipo de Cambio], [Itaca Cards]![Presupuestado OK]," 
    strQuery = strQuery & " [Itaca Cards]![Real OK], [TCpaises]![Cambio Medio], [Itaca Cards]![Fecha]" 
    strQuery = strQuery & " FROM [Itaca Cards] INNER JOIN TCpaises ON [Itaca Cards].País = TCpaises.[País Tipo de Cambio];"
    Are records returned?

  12. #12
    ssanfu is offline Master of Nothing
    Windows 2K Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    I would have expected 6 columns of data, the last which would have been a date.

    So this is a process of building the query, adding parts until the error occurs.

    Try this SQL:
    Code:
    strQuery = "SELECT [itaca cards]![país], [TCpaises]![País Tipo de Cambio], [Itaca Cards]![Presupuestado OK]," 
    strQuery = strQuery & " [Itaca Cards]![Real OK], [TCpaises]![Cambio Medio], [Itaca Cards]![Fecha],"
    strQuery = strQuery & " (TCpaises![Cambio Medio]*[Itaca Cards]![Real OK]/-1000000) AS [Real OK TC],"
    strQuery = strQuery & " (TCpaises![Cambio Medio]*[Itaca Cards]![Presupuestado OK]/-1000000) AS [Presup OK TC]"
    strQuery = strQuery & " FROM [Itaca Cards] INNER JOIN TCpaises ON [Itaca Cards].País = TCpaises.[País Tipo de Cambio];"
    If that returns records (no errors), then try:
    Code:
    strQuery = "SELECT [itaca cards]![país], [TCpaises]![País Tipo de Cambio], [Itaca Cards]![Presupuestado OK]," 
    strQuery = strQuery & " [Itaca Cards]![Real OK], [TCpaises]![Cambio Medio], [Itaca Cards]![Fecha],"
    strQuery = strQuery & " (TCpaises![Cambio Medio]*[Itaca Cards]![Real OK]/-1000000) AS [Real OK TC],"
    strQuery = strQuery & " (TCpaises![Cambio Medio]*[Itaca Cards]![Presupuestado OK]/-1000000) AS [Presup OK TC]"
    strQuery = strQuery & " FROM [Itaca Cards] INNER JOIN TCpaises ON [Itaca Cards].País = TCpaises.[País Tipo de Cambio]"
    strQuery = strQuery & " WHERE ((([Itaca Cards].Descripción)=""orex fraude"") 
    strQuery = strQuery & " AND ([Itaca Cards].Negocio =""ecr"" Or [Itaca Cards].Negocio = ""edb"");"

    (don't have to post all the records, a few will suffice )

  13. #13
    ruthib4 is offline Novice
    Windows XP Access 2003
    Join Date
    Aug 2011
    Posts
    29
    With teh first one i do get records, here they are. I am not sending you the whole list of records i am getting since it is very long.

    Argentina 0
    Argentina 0
    Argentina 0
    Argentina 0
    Argentina 0
    Argentina 0
    Argentina 0
    Argentina 0
    Argentina 0
    Argentina 0
    Argentina 0
    Argentina 0
    Argentina 0
    Argentina 0
    Argentina 0
    Argentina 0
    Argentina 0
    Argentina 0
    Argentina 0
    Argentina 0
    Argentina 0
    Argentina 0
    Argentina 0
    Argentina 0
    Argentina 0
    Argentina 0
    Argentina 0
    Argentina 0
    Argentina 0
    Argentina 0
    Argentina 0
    Argentina 0
    Argentina 0
    Argentina 0
    Argentina 0
    Argentina 0
    Argentina 0
    Argentina 0
    Argentina 0
    Chile -86772411,294
    Chile 38263410,36
    Chile 66209277,536
    Chile 161091181,532
    Chile 30066085,7067
    Chile 35258269,51
    Chile -56238227,7661
    Chile -70653768,3208
    Chile -10520563,2162
    Chile -5089100
    Chile -9714100
    Chile -8444100
    Chile 0
    Chile 0
    Chile 0

    with the second one, i do as well but different values.

    Argentina 0
    Argentina -400000
    Argentina 0
    Argentina 0
    Argentina 0
    Argentina 0
    Argentina 0
    Argentina 0
    Argentina 0
    Argentina 0
    Argentina 0
    Argentina 0
    Argentina 0
    Argentina 0
    Argentina -400000
    Argentina -400000
    Argentina -400000
    Argentina -400000
    Argentina -400000
    Argentina -400000
    Argentina -400000
    Argentina -400000
    Argentina 0
    Argentina 0
    Argentina -380000
    Argentina -400000
    Argentina -195490,6
    Argentina -397073,6
    Argentina -149607,9
    Argentina -309757,4
    Argentina -382986,7
    Argentina -287000
    Argentina -380000
    Argentina -380000
    Argentina 0
    Argentina -380000
    Argentina -400000
    Argentina -380000
    Argentina 0
    Argentina 0
    Argentina 0
    Argentina 0
    Argentina 0
    Argentina 0
    Argentina 0
    Argentina 0
    Argentina 0
    Argentina -380000
    Argentina 0
    Argentina 0
    Argentina -400000
    Argentina 0
    Argentina -977500

    cheers SSANFU


    Quote Originally Posted by ssanfu View Post
    I would have expected 6 columns of data, the last which would have been a date.

    So this is a process of building the query, adding parts until the error occurs.

    Try this SQL:
    Code:
    strQuery = "SELECT [itaca cards]![país], [TCpaises]![País Tipo de Cambio], [Itaca Cards]![Presupuestado OK]," 
    strQuery = strQuery & " [Itaca Cards]![Real OK], [TCpaises]![Cambio Medio], [Itaca Cards]![Fecha],"
    strQuery = strQuery & " (TCpaises![Cambio Medio]*[Itaca Cards]![Real OK]/-1000000) AS [Real OK TC],"
    strQuery = strQuery & " (TCpaises![Cambio Medio]*[Itaca Cards]![Presupuestado OK]/-1000000) AS [Presup OK TC]"
    strQuery = strQuery & " FROM [Itaca Cards] INNER JOIN TCpaises ON [Itaca Cards].País = TCpaises.[País Tipo de Cambio];"
    If that returns records (no errors), then try:
    Code:
    strQuery = "SELECT [itaca cards]![país], [TCpaises]![País Tipo de Cambio], [Itaca Cards]![Presupuestado OK]," 
    strQuery = strQuery & " [Itaca Cards]![Real OK], [TCpaises]![Cambio Medio], [Itaca Cards]![Fecha],"
    strQuery = strQuery & " (TCpaises![Cambio Medio]*[Itaca Cards]![Real OK]/-1000000) AS [Real OK TC],"
    strQuery = strQuery & " (TCpaises![Cambio Medio]*[Itaca Cards]![Presupuestado OK]/-1000000) AS [Presup OK TC]"
    strQuery = strQuery & " FROM [Itaca Cards] INNER JOIN TCpaises ON [Itaca Cards].País = TCpaises.[País Tipo de Cambio]"
    strQuery = strQuery & " WHERE ((([Itaca Cards].Descripción)=""orex fraude"") 
    strQuery = strQuery & " AND ([Itaca Cards].Negocio =""ecr"" Or [Itaca Cards].Negocio = ""edb"");"

    (don't have to post all the records, a few will suffice )

  14. #14
    ssanfu is offline Master of Nothing
    Windows 2K Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    What does the message box say after executing the following code?
    New lines are Blue.
    Record count should be 0 or 1

    Code:
    Private Sub summary()
       Dim Rst As ADODB.Recordset
       Dim cn As ADODB.Connection
       Dim strQuery As String
       Dim Temp As Variant
       Dim N As Long
       Dim m As Integer
    
       Fecha3 = SQLDate(reportdate1)
       FechaDesde = SqlDate1(reportdate2)
    
       Set Rst = New ADODB.Recordset
    
       strQuery = "SELECT [itaca cards]!país, Sum(TCpaises![Cambio Medio]*[Itaca Cards]![Real OK]/-1000000) AS [Real OK TC],"
       strQuery = strQuery & " Sum(TCpaises![Cambio Medio]*[Itaca Cards]![Presupuestado OK]/-1000000) AS [Presup OK TC]"
       strQuery = strQuery & " FROM [Itaca Cards] INNER JOIN TCpaises ON [Itaca Cards].País = TCpaises.[País Tipo de Cambio]"
       strQuery = strQuery & " WHERE ((([Itaca Cards].Descripción)=""orex fraude"")"
       strQuery = strQuery & " AND (([Itaca Cards].Fecha) between " & FechaDesde & " And " & Fecha3 & ")"
       strQuery = strQuery & " AND (([Itaca Cards].Negocio)= ""ecr"" Or ([Itaca Cards].Negocio)= ""edb""))"
       strQuery = strQuery & " GROUP BY [Itaca Cards].País;"
    
       Rst.Open strQuery, CurrentProject.Connection, adOpenStatic, adLockOptimistic
    
       '----------------------
       MsgBox "Record count = " & Rst.RecordCount   'comment out or delete after debugging
       '----------------------
    
       If (Rst.BOF And Rst.EOF) Then
          MsgBox "No records"
       Else
          Temp = Rst.GetRows
          With Me
             .ar1 = Temp(1, N)
             .ar2 = Temp(2, N)
             .br1 = Temp(1, N + 1)
             .br2 = Temp(2, N + 1)
             .ch1 = Temp(1, N + 2)
             .ch2 = Temp(2, N + 2)
             .co1 = Temp(1, N + 3)
             .co2 = Temp(2, N + 3)
             .es1 = Temp(1, N + 4)
             .es2 = Temp(2, N + 4)
             .us1 = Temp(1, N + 5)
             .us2 = Temp(2, N + 5)
             .me1 = Temp(1, N + 6)
             .me2 = Temp(2, N + 6)
             .po1 = Temp(1, N + 8)
             .po2 = Temp(2, N + 8)
             .pol1 = Temp(1, N + 7)
             .pol2 = Temp(2, N + 7)
             .pu1 = Temp(1, N + 9)
             .pu2 = Temp(2, N + 9)
             .uk1 = Temp(1, N + 10)
             .uk2 = Temp(2, N + 10)
          End With
       End If
    
       Rst.Close
       Set Rst = Nothing
    End Sub

  15. #15
    ruthib4 is offline Novice
    Windows XP Access 2003
    Join Date
    Aug 2011
    Posts
    29
    It says when regional settings are in my country (Spain) "dd/mm/yyyy" Record Count = 11, when using Poland's or US Record Count = 0

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Conditional Formatting on Dates
    By jpicard in forum Access
    Replies: 12
    Last Post: 11-02-2011, 03:36 PM
  2. Conditional Formatting Problem
    By DanKoz in forum Access
    Replies: 6
    Last Post: 10-23-2011, 12:57 AM
  3. Using Conditional Formatting & Dates
    By djclntn in forum Forms
    Replies: 14
    Last Post: 04-12-2011, 07:04 PM
  4. Replies: 12
    Last Post: 03-09-2011, 04:16 PM
  5. Formatting dates
    By John Southern in forum Programming
    Replies: 2
    Last Post: 05-21-2010, 11:19 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