problem in executing a query in vb 6.0

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • veer
    New Member
    • Jul 2007
    • 198

    problem in executing a query in vb 6.0

    Hi
    How can i execute this query in vb 6.0
    i use this query in ms-access and works but it shows the error that select statement can't be executed in vb 6.0
    please give me help
    my query is
    SELECT Yp1EOp, Count(*) AS Entry_count
    FROM master
    GROUP BY master.Yp1EOp
    ORDER BY master.Yp1EOp;

    please help me
    thanks in advance
    varinder
  • QVeen72
    Recognized Expert Top Contributor
    • Oct 2006
    • 1445

    #2
    Hi,

    If you are running the query from VB6, the Semicolon at the end may err.. so remove that..

    Try this :

    [code=oracle]
    SELECT Yp1EOp, Count(*) AS Entry_count
    FROM master
    GROUP BY Yp1EOp
    ORDER BY Yp1EOp
    [/code]

    Regards
    Veena

    Comment

    • veer
      New Member
      • Jul 2007
      • 198

      #3
      Hi
      i am using this query
      squery = " select Yp1EOp, count(*) from " & txttablename & " IN '" & txtchildMDBF & " ' Group By GROUP BY Yp1EOp ORDER BY Yp1EOp"
      dbmaster.Execut e (squery)

      the error is cannot execute select query

      where txttablename contain name of table and txtchildmdbf contain path for txttablename



      Originally posted by QVeen72
      Hi,

      If you are running the query from VB6, the Semicolon at the end may err.. so remove that..

      Try this :

      [code=oracle]
      SELECT Yp1EOp, Count(*) AS Entry_count
      FROM master
      GROUP BY Yp1EOp
      ORDER BY Yp1EOp
      [/code]

      Regards
      Veena

      Comment

      • QVeen72
        Recognized Expert Top Contributor
        • Oct 2006
        • 1445

        #4
        Hi,

        Well.. I had given you Select-Into Query..in one of my previous posts..
        in your query you are not using "INTO"....
        anyways check this :

        [code=oracle]
        squery = " select Yp1EOp, count(*) As ECount INTO " & txtchildMDBF _
        & " From " & txttablename & " Group By GROUP BY Yp1EOp ORDER BY Yp1EOp"
        dbmaster.Execut e (squery)
        [/code]

        Regards
        Veena

        Comment

        • veer
          New Member
          • Jul 2007
          • 198

          #5
          Thanks Very very much

          it is working

          with best regards
          varinder



          Originally posted by QVeen72
          Hi,

          Well.. I had given you Select-Into Query..in one of my previous posts..
          in your query you are not using "INTO"....
          anyways check this :

          [code=oracle]
          squery = " select Yp1EOp, count(*) As ECount INTO " & txtchildMDBF _
          & " From " & txttablename & " Group By GROUP BY Yp1EOp ORDER BY Yp1EOp"
          dbmaster.Execut e (squery)
          [/code]

          Regards
          Veena

          Comment

          • QVeen72
            Recognized Expert Top Contributor
            • Oct 2006
            • 1445

            #6
            Hi,

            You are WelCome..

            Regards
            Veena

            Comment

            • veer
              New Member
              • Jul 2007
              • 198

              #7
              Hi Veena
              actually i want to confirm can i transfer this table data into excel after this query which you gave me . I mean i want to show this table data into excelsheet

              i use this method but it shows error "invalid operation" on bold line

              squery = " select Yp1EOp, count(*) As ECount INTO " & txtchildMDBF _
              & " From " & txttablename & " GROUP BY Yp1EOp ORDER BY Yp1EOp"
              set rsmaster= dbmaster.openre cordset (squery) // INVALID OPERATION

              is there any way to transfer this output into excelsheet after this query


              pleassssssss help

              thanks in advance




              Originally posted by QVeen72
              Hi,

              You are WelCome..

              Regards
              Veena

              Comment

              • QVeen72
                Recognized Expert Top Contributor
                • Oct 2006
                • 1445

                #8
                Hi,

                In that case, Create a Macro in Access, and run the Macro..
                First Create a Query:

                Select Field1, Count(*) From MyTable Group By Field1 Order By Field1

                Run and save the Query say "MyQuery"

                Now create a New Macro.. set these properties:
                Action =OutputTo

                ObjectType= Query
                ObjectName = MyQuery
                OutputFormat Type :Microsoft Excel (*.xls)
                OutPut File : C:\MyExc.xls
                AutoRun = No

                and Save the Macro.. say "Macro1"
                Now Call macro from VBCode:

                [code=vb]
                Dim objAccess As New Access.Applicat ion
                With objAccess
                .OpenCurrentDat abase "C:\MyDb.md b"
                .DoCmd.RunMacro "Macro1", 1
                .CloseCurrentDa tabase
                End With
                Set objAccess = Nothing
                [/code]


                So all the Records of the Query are exported to Excel : C:\MyExc.xls


                Regards
                Veena

                Comment

                • veer
                  New Member
                  • Jul 2007
                  • 198

                  #9
                  Thnaks very much for helping
                  with best regards
                  varinder



                  Originally posted by QVeen72
                  Hi,

                  In that case, Create a Macro in Access, and run the Macro..
                  First Create a Query:

                  Select Field1, Count(*) From MyTable Group By Field1 Order By Field1

                  Run and save the Query say "MyQuery"

                  Now create a New Macro.. set these properties:
                  Action =OutputTo

                  ObjectType= Query
                  ObjectName = MyQuery
                  OutputFormat Type :Microsoft Excel (*.xls)
                  OutPut File : C:\MyExc.xls
                  AutoRun = No

                  and Save the Macro.. say "Macro1"
                  Now Call macro from VBCode:

                  [code=vb]
                  Dim objAccess As New Access.Applicat ion
                  With objAccess
                  .OpenCurrentDat abase "C:\MyDb.md b"
                  .DoCmd.RunMacro "Macro1", 1
                  .CloseCurrentDa tabase
                  End With
                  Set objAccess = Nothing
                  [/code]


                  So all the Records of the Query are exported to Excel : C:\MyExc.xls


                  Regards
                  Veena

                  Comment

                  • veer
                    New Member
                    • Jul 2007
                    • 198

                    #10
                    Hi
                    i am facing a little bit of probleum
                    actually i want to execute more than one macro but the output should be
                    in one file
                    the execution is ok but when i execute macro2 then output of macro1 is deleted
                    is there any way so that the output of macro1 is also remain with the output of macro2

                    please help meeeeeeeeeee

                    Comment

                    Working...