MyTetra Share
Делитесь знаниями!
Проверить наличие запроса-таблицы
Время создания: 16.03.2019 23:43
Текстовые метки: VBA, DAO, QueryDefs
Раздел: !Закладки - VBA - Access - DAO
Запись: xintrea/mytetra_db_adgaver_new/master/base/15309893560qo6v2i32a/text.html на raw.githubusercontent.com

'======================================================================================

'##### Проверить наличие запроса/таблицы

'http://www.programmersforum.ru/showthread.php?t=89869

'Sub testObjExists()

'    Set db = OpenDatabase("путь")

'    ff = FnObjExists(db, "Query", "nn1")  '"Table", "Query",

'    Set db = Nothing

'End Sub

'--------------------------------------------------------------------------------------

Public Function FnObjExists(ByVal db As Object, _

                            ByVal strObjType As String, _

                            ByVal strObjName As String) As Boolean

    On Error Resume Next

    Err.Clear

   

    Select Case strObjType

        Case "Table": FnObjExists = (db.TableDefs(strObjName).Name = strObjName)

        Case "Query": FnObjExists = (db.QueryDefs(strObjName).Name = strObjName)

        Case Else: FnObjExists = (db.Containers(strObjType & "s").Documents(strObjName).Name = strObjName)

    End Select

   

    If Len(Err.Description) = 0 Then

        FnObjExists = True

    Else

        Debug.Print Err.Description

    End If

End Function

 

'======================================================================================

 

'======================================================================================

'##### Проверка существования таблицы

'

'--------------------------------------------------------------------------------------

Public Function IsTable(ByVal NameTable As String) As Boolean

   On Error GoTo IsTable_Err

   Dim var

   var = DCount("*", NameTable)

   IsTable = True

   Exit Function

IsTable_Err:

   Select Case Err.Number

      Case 3078

         IsTable = False

      Case Else

         MsgBox Err.Number & " " & Err.Description

   End Select

End Function

'--------------------------------------------------------------------------------------

Public Function IsTable2(ByVal NameTable As String) As Boolean

   Dim i As Integer

   IsTable2 = False

   For i = 0 To CurrentDb.TableDefs.Count - 1

      If CurrentDb.TableDefs(i).Name = NameTable Then IsTable2 = True

   Next i

End Function

'======================================================================================

 

Так же в этом разделе:
 
MyTetra Share v.0.58
Яндекс индекс цитирования