How to check that a DAO exists

aziz rasul

Active member
Local time
Today, 06:06
Joined
Jun 26, 2000
Messages
1,935
I want to find a way to check whether a DAO exists before deleting it. Is there a way of obtaining a list of DAO's using VBA?
 
Do you mean "DAO reference(s)"?

You can loop through the references collection to see which libraries are referenced... ex.:

For Each ref In Application.References
If ref.Name = "dao" Then
References.Remove ref
Exit For
End If
Next

Hope this helps,

Peter De Baets
Peter's Software - MS Access tools for developers http://www.peterssoftware.com
 
Peter I don't think I made myself clear. What I was after was, by using VBA, to find out if a particular table or some other DAO object exists before deleting it.
 
Hi aziz
I have found code that shows what objects are in a given collection, and to delete an object from a collection - in the Access DAO help.
Search for: TableDef Object, TableDefs Collection Summary and then goto Name and then choose DAO example:

**************************
This example uses the Name property to give a name to a newly created object, **to show what objects are in a given collection, and to delete an object from a collection****.

Sub NameX()

Dim dbsNorthwind As Database
Dim qdfNew As QueryDef
Dim qdfLoop As QueryDef

Set dbsNorthwind = OpenDatabase("Northwind.mdb")

With dbsNorthwind
' Create a new permanent QueryDef object and append it
' to the QueryDefs collection.
Set qdfNew = .CreateQueryDef()
qdfNew.Name = "NewQueryDef"
qdfNew.SQL = "SELECT * FROM Employees"
.QueryDefs.Append qdfNew

' Enumerate the QueryDefs collection to display the
' names of the QueryDef objects.
Debug.Print "Names of queries in " & .Name

For Each qdfLoop In .QueryDefs
Debug.Print " " & qdfLoop.Name
Next qdfLoop

' Delete new QueryDef object because this is a
' demonstration.
.QueryDefs.Delete qdfNew.Name

.Close
End With

End Sub

hth

Helena
 
Helena,

Thanks for that. It worked and I learned how to use querydefs.
 

Users who are viewing this thread

Back
Top Bottom