A Microsoft Office (Excel, Word) forum. OfficeFrustration

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.

Go Back   Home » OfficeFrustration forum » Microsoft Access » General Discussion
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

VBA code for table deletion



 
 
Thread Tools Display Modes
  #1  
Old July 8th, 2009, 07:02 PM posted to microsoft.public.access
Smigidy
external usenet poster
 
Posts: 20
Default 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  
Old July 8th, 2009, 07:06 PM posted to microsoft.public.access
Douglas J. Steele[_3_]
external usenet poster
 
Posts: 3,143
Default 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  
Old July 8th, 2009, 07:13 PM posted to microsoft.public.access
Roger Carlson
external usenet poster
 
Posts: 824
Default 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  
Old July 8th, 2009, 07:40 PM posted to microsoft.public.access
Smigidy
external usenet poster
 
Posts: 20
Default 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  
Old July 8th, 2009, 07:40 PM posted to microsoft.public.access
Smigidy
external usenet poster
 
Posts: 20
Default 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  
Old July 8th, 2009, 08:32 PM posted to microsoft.public.access
Douglas J. Steele[_3_]
external usenet poster
 
Posts: 3,143
Default 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  
Old July 8th, 2009, 08:34 PM posted to microsoft.public.access
Douglas J. Steele[_3_]
external usenet poster
 
Posts: 3,143
Default 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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 10:46 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.