Connect with Expertise | Find Experts, Get Answers, Share Insights

Clear out A table with VBA

ChaseCox's Avatar
C
 
Join Date: Nov 2006
Location: Claksville, TN
Posts: 295
#1: Mar 5 '07
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.
Expand|Select|Wrap|Line Numbers
  1. Private Sub MakeFilter2()
  2.  
  3.     If Nz(chkv2125S, False) Then _
  4.             SizeArray(0) = 150
  5.     If Nz(chkv2125H, False) Then _
  6.             SizeArray(1) = 151
  7.     If Nz(chkv215S, False) Then _
  8.             SizeArray(2) = 180
  9.     If Nz(chkv215H, False) Then _
  10.             SizeArray(3) = 181
  11.     If Nz(chkv2175S, False) Then _
  12.             SizeArray(4) = 210
  13.     If Nz(chkv2175H, False) Then _
  14.             SizeArray(5) = 211
  15.     If Nz(chkv220S, False) Then _
  16.             SizeArray(6) = 240
  17.     If Nz(chkv220H, False) Then _
  18.             SizeArray(7) = 241
  19.     If Nz(chkv225S, False) Then _
  20.             SizeArray(8) = 300
  21.     If Nz(chkv225H, False) Then _
  22.             SizeArray(9) = 301
  23.  
  24.     End Sub
  25.  
  26.  Private Sub boxxob_Click()
  27.      Dim intI As Integer
  28.  
  29.      For intI = 0 To 9
  30.         Dim FalconAnalysis As Object
  31.         Dim tblUnitSize As Object
  32.         Dim colSize As Object
  33.         Set FalconAnalysis = CurrentDb
  34.         Dim UnitSize As Recordset
  35.         Set UnitSize = FalconAnalysis.OpenRecordset("UnitSize", dbOpenTable)
  36.         Dim strStringArray()
  37.         If SizeArray(intI) = 0 Then
  38.         Else
  39.         UnitSize.AddNew
  40.         UnitSize.Fields(0).Value = SizeArray(intI)
  41.         UnitSize.Update
  42.         UnitSize.Close
  43.           End If
  44.      Next
  45.  
  46.  
  47. End Sub
  48.  
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's Avatar
E
C
 
Join Date: Sep 2006
Posts: 158
#2: Mar 5 '07

re: Clear out A table with VBA


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

Docmd.runSQL "DELETE UnitSize.* FROM UnitSize;"
ChaseCox's Avatar
C
 
Join Date: Nov 2006
Location: Claksville, TN
Posts: 295
#3: Mar 5 '07

re: Clear out A table with VBA


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!!!!
Rabbit's Avatar
E
C
 
Join Date: Jan 2007
Location: California
Posts: 3,835
#4: Mar 5 '07

re: Clear out A table with VBA


Expand|Select|Wrap|Line Numbers
  1. DoCmd.SetWarnings False
  2. DoCmd.RunSQL ...
  3. DoCmd.SetWarnings True
ChaseCox's Avatar
C
 
Join Date: Nov 2006
Location: Claksville, TN
Posts: 295
#5: Mar 5 '07

re: Clear out A table with VBA


Thank you very much
Rabbit's Avatar
E
C
 
Join Date: Jan 2007
Location: California
Posts: 3,835
#6: Mar 5 '07

re: Clear out A table with VBA


No problem.
Reply