delete all the records in the temporary tables automatically

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mseo
    New Member
    • Oct 2009
    • 183

    delete all the records in the temporary tables automatically

    hi,
    I have a form that fills the temporary table in some conditions, so, is there any way to delete all the records in that temporary table dynamically (using functions or on an action

    appreciate any suggestions
    thank you
  • MMcCarthy
    Recognized Expert MVP
    • Aug 2006
    • 14387

    #2
    The following statement should work ...

    Code:
    DoCmd.RunSQL "DELETE FROM TableName"

    Comment

    • jimatqsi
      Moderator Top Contributor
      • Oct 2006
      • 1293

      #3
      You could put this in the forms close event, supplying the correct table name

      Code:
      dim strSQL as string
      strSQL = "Delete * from tablename"
      docmd.RunSQL strSQL
      Jim

      Comment

      • jimatqsi
        Moderator Top Contributor
        • Oct 2006
        • 1293

        #4
        Mary, looks like we're on the same wavelength :)

        Comment

        • MMcCarthy
          Recognized Expert MVP
          • Aug 2006
          • 14387

          #5
          Originally posted by jimatqsi
          Mary, looks like we're on the same wavelength :)
          LOL, great minds and all that!

          Comment

          • mseo
            New Member
            • Oct 2009
            • 183

            #6
            thank you
            Code:
            dim ssql As String
                DoCmd.SetWarnings False
                             ssql = "DELETE * FROM tbl_OrderTEMP"
                             ssql = "DELETE * FROM tbl_OrderDetailTEMP"
                             DoCmd.RunSQL ssql
                DoCmd.SetWarnings True
            just one table gets deleted and this table is the first declared table
            when I tried to declare another variable to excute the delete of the other table the same result
            any suggestion

            Comment

            • MMcCarthy
              Recognized Expert MVP
              • Aug 2006
              • 14387

              #7
              Originally posted by mseo
              thank you
              Code:
              dim ssql As String
                  DoCmd.SetWarnings False
                               ssql = "DELETE * FROM tbl_OrderTEMP"
                               ssql = "DELETE * FROM tbl_OrderDetailTEMP"
                               DoCmd.RunSQL ssql
                  DoCmd.SetWarnings True
              just one table gets deleted and this table is the first declared table
              when I tried to declare another variable to excute the delete of the other table the same result
              any suggestion
              You need to run the sql each time ...

              Code:
              Dim ssql As String 
              
                  DoCmd.SetWarnings False 
                  
                  ssql = "DELETE * FROM tbl_OrderTEMP"
                  DoCmd.RunSQL ssql
              
                  ssql = "DELETE * FROM tbl_OrderDetailTEMP" 
                  DoCmd.RunSQL ssql
              
                  DoCmd.SetWarnings True

              Comment

              • mseo
                New Member
                • Oct 2009
                • 183

                #8
                Originally posted by msquared
                You need to run the sql each time ...

                Code:
                Dim ssql As String 
                
                    DoCmd.SetWarnings False 
                    
                    ssql = "DELETE * FROM tbl_OrderTEMP"
                    DoCmd.RunSQL ssql
                
                    ssql = "DELETE * FROM tbl_OrderDetailTEMP" 
                    DoCmd.RunSQL ssql
                
                    DoCmd.SetWarnings True
                thank you
                it works fine
                I just need to know, if I can Create temp table using vba and after insert the data into it replace the delete line with drop code
                I just need to know if it could be done or not
                appreciate your help

                Comment

                • MMcCarthy
                  Recognized Expert MVP
                  • Aug 2006
                  • 14387

                  #9
                  Originally posted by mseo
                  thank you
                  it works fine
                  I just need to know, if I can Create temp table using vba and after insert the data into it replace the delete line with drop code
                  I just need to know if it could be done or not
                  appreciate your help
                  If you are asking me if you can do this ...

                  Code:
                      DoCmd.RunSQL "DROP TABLE tbl_OrderTEMP;"
                  Then the answer is yes :)

                  Comment

                  • mseo
                    New Member
                    • Oct 2009
                    • 183

                    #10
                    Originally posted by msquared
                    If you are asking me if you can do this ...

                    Code:
                        DoCmd.RunSQL "DROP TABLE tbl_OrderTEMP;"
                    Then the answer is yes :)
                    thank you again and over again
                    could be more than one table, if so
                    the steps would be like:
                    1- create the temp tables
                    2- insert data in the base tables or temp tables
                    3- drop the temp tables

                    Comment

                    • MMcCarthy
                      Recognized Expert MVP
                      • Aug 2006
                      • 14387

                      #11
                      More or less, there are various different approaches to take from SQL as we've used here to setting up VBA objects using TableDefs. The approach to take depends on what you are doing at the time.

                      Comment

                      Working...