Каталог статей
Создание хранимого запроса.
Dim dbs As Database
Dim qdf As QueryDef
Dim strQuery As String
Set dbs = CurrentDB
strQuery = "qry_Test1"
' Создание запроса QueryDef.
Set qdf = dbs.CreateQueryDef(strQuery, "SELECT * FROM tbl_Example1")
Set qdf = Nothing
Set dbs = Nothing
Вариант 2
Dim dbs As Database
Dim qdf As QueryDef
Set dbs = CurrentDB
' Создание запроса QueryDef.
Set qdf = dbs.CreateQueryDef
qdf.Name = "qry_Test1"
qdf.Connect = "" ' текущая база данных
qdf.SQL = "SELECT * FROM tbl_Example1"
CurrentDb.QueryDefs.Append qdf
' обновление коллекции QueryDefs
CurrentDb.QueryDefs.Refresh
Set qdf = Nothing
Set dbs = Nothing
Dim cat As ADOX.Catalog
Dim cmd As ADODB.Command
Dim strQuery As String
Set cat = New ADOX.Catalog
Set cmd = New ADODB.Command
strQuery = "qry_Test2"
cat.ActiveConnection = CurrentProject.Connection
cmd.CommandText = "SELECT * FROM tbl_Example1"
cat.Views.Append strQuery, cmd
Set cmd = Nothing
Set cat = Nothing
Dim dbs As Database
Dim strQuery As String
Set dbs = CurrentDb
strQuery = "qry_Test1"
dbs.QueryDefs(strQuery).SQL = "SELECT Familia FROM tbl_Example1"
Set dbs = Nothing
Dim cat As ADOX.Catalog
Dim strQuery As String
Set cat = New ADOX.Catalog
strQuery = "qry_Test2"
cat.ActiveConnection = CurrentProject.Connection
cat.Views(strQuery).Command = "SELECT Name1 FROM tbl_Example1" 'cmd
Set cat = Nothing
Dim dbs As Database
Dim qdf As QueryDef
Dim strQuery As String
Set dbs = CurrentDb
strQuery = "qry_Test1"
dbs.QueryDefs.Delete strQuery
Set qdf = Nothing
Set dbs = Nothing
Dim cat As ADOX.Catalog
Dim strQuery As String
Set cat = New ADOX.Catalog
strQuery = "qry_Test2"
cat.ActiveConnection = CurrentProject.Connection
cat.Views.Delete strQuery
Set cat = Nothing
Dim dbs As Database
Dim qdf As QueryDef
Dim strQuery As String
Set dbs = CurrentDb
strQuery = "qry_Test1"
For Each qdf In dbs.QueryDefs
If qdf.Name = strQuery Then
Debug.Print "Запрос " & strQuery & " есть"
Exit For
End If
Next
Set qdf = Nothing
Set dbs = Nothing
Dim cat As ADOX.Catalog
Dim qry As ADOX.View
Dim strQuery As String
Set cat = New ADOX.Catalog
strQuery = "qry_Test2"
cat.ActiveConnection = CurrentProject.Connection
For Each qry In cat.Views
If qry.Name = strQuery Then
Debug.Print "Запрос " & strQuery & " есть"
Exit For
End If
Next
Set qry = Nothing
Set cat = Nothing
Set dbs = OpenDatabase("Northwind.mdb")
После работы базу необходимо закрыть
dbs.Close
' Открыть каталог
cat.ActiveConnection = _
"Provider='Microsoft.Jet.OLEDB.4.0';" & _
"Data Source='Northwind.mdb';"
' Открыть каталог
cat.ActiveConnection = _
"Provider='Microsoft.ACE.OLEDB.12.0';" & _
"Data Source='Northwind.mdb';"
| |
Просмотров: 234 | | |
Всего комментариев: 0 | |