Buonasera,
sono a chiedere un aiuto in relazione a questo problema. Nella procedura che allego vado a leggere su un db esterno tutte le form presenti. In alcune di queste ci sono degli errori di run-time, per la precisione 3078, ma solo il primo di questi mi viene intercettato da Err_Handler, negli altri casi mi mostra la solita finestra di messaggio di Warning e non entra nel controllo degli errori.
Ringrazio in anticipo chi mi può dare una mano.
Sub testFormEsterno()
On Error GoTo Err_Handler
Dim obj As AccessObject
Dim accapp As Access.Application
Dim CP As CodeProject
Set accapp = New Access.Application
Dim frm As Access.Form
Dim rs As Recordset
Dim ctl As Control
Dim fld As Field
Dim prp As Property
Dim Sql As Variant
''' Apro db esterno
accapp.OpenCurrentDatabase ("C:\Archivio\Access\database1.accdb")
Set CP = accapp.CurrentProject
''' Itero tutti i nome delle Form
For Each obj In CP.AllForms
Debug.Print obj.Name
''' Apro la Form su Db esterno
accapp.DoCmd.OpenForm obj.Name, acDesign, WindowMode:=acHidden
''' Apro il set
Set frm = accapp.Forms(obj.Name)
Debug.Print frm.Properties(Sql)
''' Scarto le form senza sql
If Len(frm.Properties(Sql)) = 0 Then GoTo controlli
Set rs = DBEngine(0)(0).OpenRecordset(frm.Properties(Sql))
''' Leggo i nomi di campi e tabelle contenute in SQL
For Each fld In rs.Fields
' Debug.Print obj.Name, frm.Name, fld.SourceTable, fld.Name, FieldTypeName(fld)
Next
controlli:
''' leggo i controlli della form
For Each ctl In frm
If ctl.Properties("ControlType") >= 105 And ctl.Properties("ControlType") <= 122 Then
Debug.Print ctl.Name, ctl.Properties("ControlType"), ctl.Properties("Visible"), , ctl.Properties("Enabled"), ctl.Properties("Tag"), ctl.Properties("ControlSource")
End If
Next ctl
''' Chiudo la form
fine:
accapp.DoCmd.Close acForm, obj.Name, acSaveNo
Set rs = Nothing
Next obj
Exit_Handler:
accapp.CloseCurrentDatabase
Set frm = Nothing
Set rs = Nothing
Set CP = Nothing
Exit Sub
Err_Handler:
If Err.Number = 2467 Then
Debug.Print "scrivi errore" & Err.Number & ": " & Left(Err.Description, InStr(1, Err.Description, ".") - 1)
GoTo fine
ElseIf Err.Number = 3078 Then
Debug.Print "scrivi errore" & Err.Number & ": " & Left(Err.Description, InStr(1, Err.Description, ".") - 1)
Err.Clear
GoTo controlli
Else
Debug.Print "scrivi errore" & Err.Number & ": " & Left(Err.Description, InStr(1, Err.Description, ".") - 1)
GoTo Exit_Handler
End If
End Sub