|
|
Проверка на наличие таблицы в текущей БД (Fields.Сount) DAO и ADO
DAO
Public Function IsTablePresentDAO(strTableName As String) As Boolean
Dim iVal As Integer
On Error GoTo IsTablePresentDAO_Err
iVal = CurrentDb.TableDefs(strTableName).Fields.Count
If iVal > 0 Then IsTablePresentDAO = True
IsTablePresentDAO_Bye:
Exit Function
IsTablePresentDAO_Err:
Select Case Err.Number
Case 3265
Case Else
"in procedure IsTablePresentDAO", vbCritical, "Error!"
End Select
Err.Clear
Resume IsTablePresentDAO_Bye
End Function
ADO
Public Function IsTablePresentADO(sTableName As String) As Boolean
Dim rst As New ADODB.Recordset
Dim sSQL$, iFildsCount
On Error GoTo IsTablePresentADO_Err
Set rst = CreateObject("ADODB.Recordset")
sSQL = "SELECT * FROM " & sTableName
rst.Open sSQL, CurrentProject.Connection, adOpenStatic, adLockReadOnly
iFildsCount = rst.Fields.Count
If iFildsCount > 0 Then IsTablePresentADO = True
IsTablePresentADO_End:
On Error Resume Next
rst.Close
Set rst = Nothing
Err.Clear
Exit Function
IsTablePresentADO_Err:
Err.Clear
Resume IsTablePresentADO_End
End Function
|
|