Clear out A table with VBA

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ChaseCox
    Contributor
    • Nov 2006
    • 293

    Clear out A table with VBA

    I would like to clear out all the records of a table using VB Code. I am building the table on the fly, so that I can cross reference it with my main table. The table consits of a multiple 3 digit numbers, depending on the check box the user clicks.

    The DB name is FalconAnalysis, the table name is UnitSize and the only field in the table is Size. Here is the Code I am using, the first builds my array based on the check boxes, and the second part passes the values into my table as long as they are not zero.
    Code:
    Private Sub MakeFilter2()
                      
        If Nz(chkv2125S, False) Then _
                SizeArray(0) = 150
        If Nz(chkv2125H, False) Then _
                SizeArray(1) = 151
        If Nz(chkv215S, False) Then _
                SizeArray(2) = 180
        If Nz(chkv215H, False) Then _
                SizeArray(3) = 181
        If Nz(chkv2175S, False) Then _
                SizeArray(4) = 210
        If Nz(chkv2175H, False) Then _
                SizeArray(5) = 211
        If Nz(chkv220S, False) Then _
                SizeArray(6) = 240
        If Nz(chkv220H, False) Then _
                SizeArray(7) = 241
        If Nz(chkv225S, False) Then _
                SizeArray(8) = 300
        If Nz(chkv225H, False) Then _
                SizeArray(9) = 301
        
        End Sub
        
     Private Sub boxxob_Click()
         Dim intI As Integer
       
         For intI = 0 To 9
            Dim FalconAnalysis As Object
            Dim tblUnitSize As Object
            Dim colSize As Object
            Set FalconAnalysis = CurrentDb
            Dim UnitSize As Recordset
            Set UnitSize = FalconAnalysis.OpenRecordset("UnitSize", dbOpenTable)
            Dim strStringArray()
            If SizeArray(intI) = 0 Then
            Else
            UnitSize.AddNew
            UnitSize.Fields(0).Value = SizeArray(intI)
            UnitSize.Update
            UnitSize.Close
              End If
         Next
     
    
    End Sub
    If this is possible, or not, please let me know. I have been trying to use the Delete comand with no success. Thanks for the help.
  • MSeda
    Recognized Expert New Member
    • Sep 2006
    • 159

    #2
    The following command will delete all records unconditionally from the table named UnitSize.

    Docmd.runSQL "DELETE UnitSize.* FROM UnitSize;"

    Comment

    • ChaseCox
      Contributor
      • Nov 2006
      • 293

      #3
      Originally posted by MSeda
      The following command will delete all records unconditionally from the table named UnitSize.

      Docmd.runSQL "DELETE UnitSize.* FROM UnitSize;"

      Thanks! is there a way to not have the warning about deleting the records from showing up.

      CHEERS!!!!

      Comment

      • Rabbit
        Recognized Expert MVP
        • Jan 2007
        • 12517

        #4
        Code:
        DoCmd.SetWarnings False
        DoCmd.RunSQL ...
        DoCmd.SetWarnings True

        Comment

        • ChaseCox
          Contributor
          • Nov 2006
          • 293

          #5
          Thank you very much

          Comment

          • Rabbit
            Recognized Expert MVP
            • Jan 2007
            • 12517

            #6
            No problem.

            Comment

            Working...