Results 1 to 3 of 3
  1. #1
    ravininave is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Mar 2015
    Posts
    11

    Access Query Error


    This is my Query which I am running from Visual Basic 6 but count function returning wrong count

    Rs.Open "SELECT 1 as rowno, AgentCode, AgentName, TotalAg, Amount,MainAmt, DiscAmt,CommAmt,TdAmt, NewTDSAmt, CommAmt - " & (TdAmt + NewTDSAmt) & " as lAmt, Commission FROM (" _
    & "Select AgentCode, AgentName, TotalAg, Amount,MainAmt, DiscAmt,CommAmt,CommAmt * " & TDSAmtFromMast & " / 100 as TdAmt, CommAmt * " & NewTDSAmt & "/ 100 as NewTDSAmt, Commission from (" _
    & "Select Comms.AgentCode, AgentName, Count(Registration.AgentCode) as TotalAg, sum(Amount) as Amount,sum(MainAmt) as MainAmt, sum(DiscAmt) as DiscAmt,sum(CommAmt) as CommAmt, AgentMast.Commission from (Comms INNER JOIN AgentMast on Comms.AgentCode = AgentMast.AgentCode ) " _
    & "LEFT JOIN JOIN Registration ON (Comms.CodeNo = Registration.CodeNo and PurchDate >=#" & CDate(FDate.Value) & "# and Purchdate <=#" & CDate(TDate.Value) & "# and Registration.AgentCode =Comms.AgentCode) WHERE ((RecDate >=#" & CDate(FDate.Value) & "# and RecDate <=#" & CDate(TDate.Value) & "# and Comms.AgentCode <>0 )) AND ((isnull(RelDate) = TRUE and (RelTag =0 or Isnull(RelTag = TRUE)))) OR (ReLDate >=#" & CDate(FDate.Value) & "# and ReLDate <=#" & CDate(TDate.Value) & "# and Comms.AgentCode <>0) Group By Comms.AgentCode, AgentMast.AgentName, AgentMast.Commission ) Test) BEST", DBConn, adOpenForwardOnly, adLockOptimistic

  2. #2
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    in what way is it wrong?

    And I don't see a count function

    Suggest also tidy your code up so it is readable, seems to be a load of virtual tables

  3. #3
    Join Date
    May 2018
    Location
    Living in Scotland UK
    Posts
    1,566
    Hi

    If you can upload a zipped copy of the database it would make it easier to help.
    You can PM me if you need further help.
    Good Reading https://docs.microsoft.com/en-gb/off...on-description

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

Similar Threads

  1. Replies: 8
    Last Post: 01-11-2020, 04:31 AM
  2. Error in Access query
    By msaccessdev in forum Programming
    Replies: 2
    Last Post: 06-17-2014, 06:50 AM
  3. Error in Access query
    By msaccessdev in forum Access
    Replies: 1
    Last Post: 06-17-2014, 03:02 AM
  4. Replies: 10
    Last Post: 02-02-2011, 05:48 PM
  5. Access query Error
    By sneupane in forum Programming
    Replies: 2
    Last Post: 03-15-2010, 03:12 PM

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