If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
VBA code for table deletion
I have the following code to delete all table data except for what is in the
Switchboard Items table, but there's a compile error. Any suggestions? Public Sub sDeleteAllTableData() Dim dbAny As DAO.Database Dim I As Long Set dbAny = CurrentDb() For I = 0 To dbAny.TableDefs.Count - 1 If (dbAny.TableDefs(I).Attributes And dbSystemObject) = 0 or If (dbany.tabledefs(i).name="Switchboard Items") Then dbAny.Execute "DELETE FROM [" & dbAny.TableDefs(I).Name & "]" End If Next I End Sub Thanks, Michael |
#2
|
|||
|
|||
VBA code for table deletion
Remove the second If:
For I = 0 To dbAny.TableDefs.Count - 1 If (dbAny.TableDefs(I).Attributes And dbSystemObject) = 0 or _ (dbany.tabledefs(i).name="Switchboard Items") Then dbAny.Execute "DELETE FROM [" & dbAny.TableDefs(I).Name & "]" End If Next I Note the line continuation character as well. Of course, if you've set Referential Integrity, your deletes may not work... -- Doug Steele, Microsoft Access MVP http://I.Am/DougSteele (no e-mails, please!) "Smigidy" wrote in message ... I have the following code to delete all table data except for what is in the Switchboard Items table, but there's a compile error. Any suggestions? Public Sub sDeleteAllTableData() Dim dbAny As DAO.Database Dim I As Long Set dbAny = CurrentDb() For I = 0 To dbAny.TableDefs.Count - 1 If (dbAny.TableDefs(I).Attributes And dbSystemObject) = 0 or If (dbany.tabledefs(i).name="Switchboard Items") Then dbAny.Execute "DELETE FROM [" & dbAny.TableDefs(I).Name & "]" End If Next I End Sub Thanks, Michael |
#3
|
|||
|
|||
VBA code for table deletion
I suggest:
Public Sub sDeleteAllTableData() Dim dbAny As DAO.Database Dim I As Long Set dbAny = CurrentDb() For I = 0 To dbAny.TableDefs.Count - 1 If dbAny.TableDefs(I).Attributes = 0 And _ dbSystemObject 0 _ Or (dbAny.TableDefs(I).Name = "Switchboard Items") Then dbAny.Execute "DELETE FROM [" & dbAny.TableDefs(I).Name & "]" End If Next I End Sub "Smigidy" wrote in message ... I have the following code to delete all table data except for what is in the Switchboard Items table, but there's a compile error. Any suggestions? Public Sub sDeleteAllTableData() Dim dbAny As DAO.Database Dim I As Long Set dbAny = CurrentDb() For I = 0 To dbAny.TableDefs.Count - 1 If (dbAny.TableDefs(I).Attributes And dbSystemObject) = 0 or If (dbany.tabledefs(i).name="Switchboard Items") Then dbAny.Execute "DELETE FROM [" & dbAny.TableDefs(I).Name & "]" End If Next I End Sub Thanks, Michael |
#4
|
|||
|
|||
VBA code for table deletion
This deleted the Switchboard Items table data as well.
"Roger Carlson" wrote: I suggest: Public Sub sDeleteAllTableData() Dim dbAny As DAO.Database Dim I As Long Set dbAny = CurrentDb() For I = 0 To dbAny.TableDefs.Count - 1 If dbAny.TableDefs(I).Attributes = 0 And _ dbSystemObject 0 _ Or (dbAny.TableDefs(I).Name = "Switchboard Items") Then dbAny.Execute "DELETE FROM [" & dbAny.TableDefs(I).Name & "]" End If Next I End Sub "Smigidy" wrote in message ... I have the following code to delete all table data except for what is in the Switchboard Items table, but there's a compile error. Any suggestions? Public Sub sDeleteAllTableData() Dim dbAny As DAO.Database Dim I As Long Set dbAny = CurrentDb() For I = 0 To dbAny.TableDefs.Count - 1 If (dbAny.TableDefs(I).Attributes And dbSystemObject) = 0 or If (dbany.tabledefs(i).name="Switchboard Items") Then dbAny.Execute "DELETE FROM [" & dbAny.TableDefs(I).Name & "]" End If Next I End Sub Thanks, Michael |
#5
|
|||
|
|||
VBA code for table deletion
This deleted the Switchboard Items table data as well.
"Douglas J. Steele" wrote: Remove the second If: For I = 0 To dbAny.TableDefs.Count - 1 If (dbAny.TableDefs(I).Attributes And dbSystemObject) = 0 or _ (dbany.tabledefs(i).name="Switchboard Items") Then dbAny.Execute "DELETE FROM [" & dbAny.TableDefs(I).Name & "]" End If Next I Note the line continuation character as well. Of course, if you've set Referential Integrity, your deletes may not work... -- Doug Steele, Microsoft Access MVP http://I.Am/DougSteele (no e-mails, please!) "Smigidy" wrote in message ... I have the following code to delete all table data except for what is in the Switchboard Items table, but there's a compile error. Any suggestions? Public Sub sDeleteAllTableData() Dim dbAny As DAO.Database Dim I As Long Set dbAny = CurrentDb() For I = 0 To dbAny.TableDefs.Count - 1 If (dbAny.TableDefs(I).Attributes And dbSystemObject) = 0 or If (dbany.tabledefs(i).name="Switchboard Items") Then dbAny.Execute "DELETE FROM [" & dbAny.TableDefs(I).Name & "]" End If Next I End Sub Thanks, Michael |
#6
|
|||
|
|||
VBA code for table deletion
Well, sure it did. You told it to! If you're trying to exclude that table,
you need to ensure that the name ISN'T that, as opposed to IS: -- Doug Steele, Microsoft Access MVP http://I.Am/DougSteele (no e-mails, please!) "Smigidy" wrote in message ... This deleted the Switchboard Items table data as well. "Douglas J. Steele" wrote: Remove the second If: For I = 0 To dbAny.TableDefs.Count - 1 If (dbAny.TableDefs(I).Attributes And dbSystemObject) = 0 or _ (dbany.tabledefs(i).name="Switchboard Items") Then dbAny.Execute "DELETE FROM [" & dbAny.TableDefs(I).Name & "]" End If Next I Note the line continuation character as well. Of course, if you've set Referential Integrity, your deletes may not work... -- Doug Steele, Microsoft Access MVP http://I.Am/DougSteele (no e-mails, please!) "Smigidy" wrote in message ... I have the following code to delete all table data except for what is in the Switchboard Items table, but there's a compile error. Any suggestions? Public Sub sDeleteAllTableData() Dim dbAny As DAO.Database Dim I As Long Set dbAny = CurrentDb() For I = 0 To dbAny.TableDefs.Count - 1 If (dbAny.TableDefs(I).Attributes And dbSystemObject) = 0 or If (dbany.tabledefs(i).name="Switchboard Items") Then dbAny.Execute "DELETE FROM [" & dbAny.TableDefs(I).Name & "]" End If Next I End Sub Thanks, Michael |
#7
|
|||
|
|||
VBA code for table deletion
Oops...hit Enter too soon.
To exclude, try something like: For I = 0 To dbAny.TableDefs.Count - 1 If (dbAny.TableDefs(I).Attributes And dbSystemObject) = 0 And _ dbany.tabledefs(i).name"Switchboard Items" Then dbAny.Execute "DELETE FROM [" & dbAny.TableDefs(I).Name & "]" End If Next I -- Doug Steele, Microsoft Access MVP http://I.Am/DougSteele (no e-mails, please!) "Smigidy" wrote in message ... This deleted the Switchboard Items table data as well. "Douglas J. Steele" wrote: Remove the second If: For I = 0 To dbAny.TableDefs.Count - 1 If (dbAny.TableDefs(I).Attributes And dbSystemObject) = 0 or _ (dbany.tabledefs(i).name="Switchboard Items") Then dbAny.Execute "DELETE FROM [" & dbAny.TableDefs(I).Name & "]" End If Next I Note the line continuation character as well. Of course, if you've set Referential Integrity, your deletes may not work... -- Doug Steele, Microsoft Access MVP http://I.Am/DougSteele (no e-mails, please!) "Smigidy" wrote in message ... I have the following code to delete all table data except for what is in the Switchboard Items table, but there's a compile error. Any suggestions? Public Sub sDeleteAllTableData() Dim dbAny As DAO.Database Dim I As Long Set dbAny = CurrentDb() For I = 0 To dbAny.TableDefs.Count - 1 If (dbAny.TableDefs(I).Attributes And dbSystemObject) = 0 or If (dbany.tabledefs(i).name="Switchboard Items") Then dbAny.Execute "DELETE FROM [" & dbAny.TableDefs(I).Name & "]" End If Next I End Sub Thanks, Michael |
Thread Tools | |
Display Modes | |
|
|