Public Function EnumReports(DbName As String, TheControl As Control) As Boolean
On Error GoTo ErrHandle Dim IntRep As Integer GetReports = False If Not Exists(DbName) Then MsgBox "Errore: " + vbCrLf + _ "Il file" + DbName + vbCrLf + _ "non esiste.", vbCritical Exit Function End If If Not TypeOf TheControl Is ListBox Then MsgBox "Errore: " + vbCrLf + _ "Il controllo non e' una ListBox", vbCritical Exit Function Else TheControl.Clear End If Screen.MousePointer = vbHourglass Set objAccess = CreateObject("Access.Application") With objAccess .OpenCurrentDatabase (DbName) Set dbs = .CurrentDb With dbs.Containers("Reports") For IntRep = 0 To .Documents.Count - 1 If Left(.Documents(IntRep).Name, 4) <> "~TMP" Then TheControl.AddItem .Documents(IntRep).Name End If Next IntRep End With End With GetReports = True Screen.MousePointer = vbDefault Exit Function ErrHandle: MsgBox "Errore #" + Str(Err.Number) + ": " + Err.Description + ".", _ vbCritical Screen.MousePointer = vbDefault End Function 'Questa funzione crea la stampa un report presente nel DB. Public Function PrintReport(WhichReport) As Boolean On Error GoTo ErrHandle 'Const acPreview = 2 'Costanti definite di Access 'Const acReport = 3 Screen.MousePointer = vbHourglass PrintReport = False If WhichReport = "" Then MsgBox "Internal Error: " + vbCrLf + _ "Report String not passed.", vbCritical, ProgTitle Exit Function End If objAccess.DoCmd.OpenReport WhichReport ', acPreview per l'anteprima 'objAccess.DoCmd.Maximize 'objAccess.DoCmd.SelectObject acReport, WhichReport PrintReport = True Screen.MousePointer = vbDefault Exit Function ErrHandle: MsgBox "Error #" + Str(Err.Number) + ": " + Err.Description + ".", _ vbCritical, ProgTitle Screen.MousePointer = vbDefault End Function Questa funzione ottiene la lista dei reports presenti nel DB e carica i loro nomi in una ListBox passatagli come argomento. Esempio di utilizzo: Flag = EnumReports("C:\MioDb.mdb",form1.list1) |