Removing Queries with Code (1 Viewer)

MikeAngelastro

Registered User.
Local time
Today, 14:45
Joined
Mar 3, 2000
Messages
254
Hi,

Does anyone know the VBA code to remove all queries, forms, reports, etc from a given Access database? Removong them manually takes too long.

Thanks,

Mike
 

dcx693

Registered User.
Local time
Today, 16:45
Joined
Apr 30, 2003
Messages
3,265
Using DAO or ADO? If you're not sure, which version of Access are you using?
 

SforSoftware

(NL) SnelStart specialist
Local time
Today, 22:45
Joined
Aug 16, 2003
Messages
239
Code:
Public Function DeleteAllTables()
  Dim tbl As Obejct

  For Each tbl in currentdata.alltables
    Docmd.deleteobject tbl.name
  next tbl
End Function
tables/queries are in currentdata, forms/reports are in currentproject
 

dcx693

Registered User.
Local time
Today, 16:45
Joined
Apr 30, 2003
Messages
3,265
I thought we were looking for DAO code. :confused:
 

SforSoftware

(NL) SnelStart specialist
Local time
Today, 22:45
Joined
Aug 16, 2003
Messages
239
No, we were looking for the question 'how to remove access-objects via code' ;)

It's also possible with DAO and ADO, but why should you make it yourself difficult if it's so easy :)

greetz,
Bert
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 21:45
Joined
Jul 9, 2003
Messages
16,426
I couldn't get it to work anyway ! :confused: :(
 

dcx693

Registered User.
Local time
Today, 16:45
Joined
Apr 30, 2003
Messages
3,265
SforSoftware said:
What's the problem you've?
If you look at my question above, I asked the user if he/she needed ADO or DAO. The user replied with "DAO". That's the problem. :)
 

SforSoftware

(NL) SnelStart specialist
Local time
Today, 22:45
Joined
Aug 16, 2003
Messages
239
okay, that seems to be your problem, but not the of uncle gizmo :p
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 21:45
Joined
Jul 9, 2003
Messages
16,426
SforSoftware said:
What's the problem you've?

Well besides the fact that I haven't got a clue how how it works, I place this code:

Code:
Public Function fConList()

 Dim tbl As Object

  For Each tbl In CurrentData.AllTables
    DoCmd.DeleteObject tbl.Name
  Next tbl

End Function

in a module and I called it with a command button on a form and I get the following error message:

This action requires an Object Name argument

Do I need to numerate the collection and loop through it ? :confused:
 

SforSoftware

(NL) SnelStart specialist
Local time
Today, 22:45
Joined
Aug 16, 2003
Messages
239
okay, you're right, my code isn't complete (because I wrote it in the forum-editor ;))
it must be:
Code:
Public Function fConList()
  Dim tbl As AccessObject
  
  For Each tbl In CurrentData.AllTables
    If Left(tbl.Name, 4) <> "msys" Then
      DoCmd.DeleteObject acTable, tbl.Name
    End If
  Next tbl
End Function
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 21:45
Joined
Jul 9, 2003
Messages
16,426
Brilliant , all of my tables have gone !

How do I get them back ?











Only joking he he he I know they are gone for good
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 16:45
Joined
Feb 19, 2002
Messages
43,774
Delete the broken db and copy the backup copy. If you are trying to split a db, there is a wizard. You don't have to do this manually. Also, if you want to split the db manually, it's easier to create a new empty db and import just the tables. Then delete the tables from the original db and add links.
 

Users who are viewing this thread

Top Bottom