an easy one

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jim

    an easy one

    anyone know how to run an append (well any query I suppose) from code.

    I'm rusty and actually have never ran a query from code.

    I'm thinking docmd.runquery( "query")

    TIA


  • Tom van Stiphout

    #2
    Re: an easy one

    On Fri, 04 Jul 2008 03:26:48 GMT, "Jim" <jimt@pioneers. cawrote:

    Not "any query", but "any action query":
    DoCmd.RunSQL

    The help file would have told you runquery is not a legal action.
    Don't use the newsgroups in lieu of the help file.

    -Tom.

    >anyone know how to run an append (well any query I suppose) from code.
    >
    >I'm rusty and actually have never ran a query from code.
    >
    >I'm thinking docmd.runquery( "query")
    >
    >TIA
    >

    Comment

    • Jim

      #3
      Re: an easy one

      Hey dude hold your fire.

      I'm not a code genius. I've been trying to find it myself in help and on the
      access web. I don't want to run SQL per se, I already have an append query
      created and just want to run it - simplifying things for myself, so I don't
      get caught up in code.

      Is this not an access (all access, not just code and SQL) newsgroup?




      "Tom van Stiphout" <no.spam.tom774 4@cox.netwrote in message
      news:m86r64l54g fujv5s5o4u47kle 40tcse77i@4ax.c om...
      On Fri, 04 Jul 2008 03:26:48 GMT, "Jim" <jimt@pioneers. cawrote:
      >
      Not "any query", but "any action query":
      DoCmd.RunSQL
      >
      The help file would have told you runquery is not a legal action.
      Don't use the newsgroups in lieu of the help file.
      >
      -Tom.
      >
      >
      >>anyone know how to run an append (well any query I suppose) from code.
      >>
      >>I'm rusty and actually have never ran a query from code.
      >>
      >>I'm thinking docmd.runquery( "query")
      >>
      >>TIA
      >>

      Comment

      • Rick Brandt

        #4
        Re: an easy one (it was easy)

        Jim wrote:
        I'll give it a try in the name of curiousity to get the sql stuff to
        work. I did finally find out a way to run a query from code with the
        command button wizard. It couldn't be simpler. When I invoked the
        command button wizard, under miscellaneous operations, there was a
        "run a query" option.
        But, I should persist in trying to make this run SQL work to, as I
        may need to use variables some day and runSQL looks for efficient in
        that sense.
        Thanks all.
        CurrentDB.Execu te "QueryName" , dbFailOnError

        That is actually better than RunSQL in most cases since it can also use a
        SQL statement in place of the query name. Better error handling and no
        confirmation prompts.

        --
        Rick Brandt, Microsoft Access MVP
        Email (as appropriate) to...
        RBrandt at Hunter dot com


        Comment

        • fredg

          #5
          Re: an easy one

          On Fri, 04 Jul 2008 03:41:36 GMT, Jim wrote:
          Hey dude hold your fire.
          >
          I'm not a code genius. I've been trying to find it myself in help and on the
          access web. I don't want to run SQL per se, I already have an append query
          created and just want to run it - simplifying things for myself, so I don't
          get caught up in code.
          >
          Is this not an access (all access, not just code and SQL) newsgroup?
          >
          "Tom van Stiphout" <no.spam.tom774 4@cox.netwrote in message
          news:m86r64l54g fujv5s5o4u47kle 40tcse77i@4ax.c om...
          >On Fri, 04 Jul 2008 03:26:48 GMT, "Jim" <jimt@pioneers. cawrote:
          >>
          >Not "any query", but "any action query":
          >DoCmd.RunSQL
          >>
          >The help file would have told you runquery is not a legal action.
          >Don't use the newsgroups in lieu of the help file.
          >>
          >-Tom.
          >>
          >>
          >>>anyone know how to run an append (well any query I suppose) from code.
          >>>
          >>>I'm rusty and actually have never ran a query from code.
          >>>
          >>>I'm thinking docmd.runquery( "query")
          >>>
          >>>TIA
          >>>
          The help files in Access are split into different sections.
          There is an Access help and a VBA help.
          Since you are dealing with code you need to look in the Code (VBA help
          ) section.
          Open any code window (or click Ctrl+G) and then click on help.
          Or you can use the Command Button wizard to add a command button to a
          form. One of the choices is to run a Query. Let it create the code,
          then examine what the wizard wrote.

          You can use the
          DoCmd.OpenQuery "QueryName"
          method...
          Or
          CurrentDb.Execu te "QueryName"

          Look them up in VBA help.
          While there, also look up SetWarnings as well.
          --
          Fred
          Please respond only to this newsgroup.
          I do not reply to personal e-mail

          Comment

          • KC-Mass

            #6
            Re: an easy one (it was easy)

            Hi Rick

            What error info will that yeild and how would it best be handled?

            Thx

            Kevin


            "Rick Brandt" <rickbrandt2@ho tmail.comwrote in message
            news:uIobk.543$ cn7.326@flpi145 .ffdc.sbc.com.. .
            Jim wrote:
            >I'll give it a try in the name of curiousity to get the sql stuff to
            >work. I did finally find out a way to run a query from code with the
            >command button wizard. It couldn't be simpler. When I invoked the
            >command button wizard, under miscellaneous operations, there was a
            >"run a query" option.
            >But, I should persist in trying to make this run SQL work to, as I
            >may need to use variables some day and runSQL looks for efficient in
            >that sense.
            >Thanks all.
            >
            CurrentDB.Execu te "QueryName" , dbFailOnError
            >
            That is actually better than RunSQL in most cases since it can also use a
            SQL statement in place of the query name. Better error handling and no
            confirmation prompts.
            >
            --
            Rick Brandt, Microsoft Access MVP
            Email (as appropriate) to...
            RBrandt at Hunter dot com
            >

            Comment

            • Rick Brandt

              #7
              Re: an easy one (it was easy)

              KC-Mass wrote:
              Hi Rick
              >
              What error info will that yeild and how would it best be handled?
              The typical problems that can occur when running an action query will prompt
              the user with RunSQL, but they are not treated as errors "to your code". If
              your code needs to know whether everything went well with the query then the
              Execute method is the way to go. These include (but are not limited to)...

              Inserting/Updating a row that violates a unique index (duplicate)
              Inserting/Updating a row missing a required field value
              Inserting a child row without a matching parent row in a related table (RI
              enabled)
              Deleting a parent row when there are still dependent children rows (RI
              enabled but not cascade delete)


              --
              Rick Brandt, Microsoft Access MVP
              Email (as appropriate) to...
              RBrandt at Hunter dot com


              Comment

              • KC-Mass

                #8
                Re: an easy one (it was easy)

                Thanks much - good info.

                "Rick Brandt" <rickbrandt2@ho tmail.comwrote in message
                news:Kbwck.3003 $cn7.2516@flpi1 45.ffdc.sbc.com ...
                KC-Mass wrote:
                >Hi Rick
                >>
                >What error info will that yeild and how would it best be handled?
                >
                The typical problems that can occur when running an action query will
                prompt the user with RunSQL, but they are not treated as errors "to your
                code". If your code needs to know whether everything went well with the
                query then the Execute method is the way to go. These include (but are
                not limited to)...
                >
                Inserting/Updating a row that violates a unique index (duplicate)
                Inserting/Updating a row missing a required field value
                Inserting a child row without a matching parent row in a related table (RI
                enabled)
                Deleting a parent row when there are still dependent children rows (RI
                enabled but not cascade delete)
                >
                >
                --
                Rick Brandt, Microsoft Access MVP
                Email (as appropriate) to...
                RBrandt at Hunter dot com
                >

                Comment

                Working...