18 June 2013

Show/Hide All MS Access Objects

Vari modi per visualizzare/nascondere tutti gli oggetti di MS Access.



Basato su un'idea trovata qui. Non ancora testata al 100%!!:
Public Function Boso()
    
    Dim o As AccessObject
    
    For Each o In CurrentProject.AllForms
        Debug.Print o.Name
        Application.SetHiddenAttribute o.Type, o.Name, False
    Next
    
End Function



Public Sub HideObjects(Optional booHide As Boolean)
    
    'Created by Speakers_86
    'You are free to use, modify, and distribute
    'this as long as you leave this comment
    '
    'Purpose:   loops through all of you access objects, and
    '           hides them, the same as using the Access Gui to
    '           hide an object
    'Argument:  booHide
    '           an optional argument.  True hides objects,
    '           false unhides objects
    

    Dim db     As Database
    Dim tbl    As TableDef
    Dim qry    As QueryDef
    Dim str    As String
    Dim i      As Integer

    On Error Resume Next
    
    Set db = CurrentDb()


    For Each tbl In db.TableDefs
            Call SetHiddenAttribute(acTable, tbl.Name, booHide)
    Next tbl


    For Each qry In db.QueryDefs
        Call SetHiddenAttribute(acQuery, qry.Name, booHide)
    Next qry


    For i = 0 To db.Containers("Forms").Documents.Count - 1
        str = db.Containers("Forms").Documents(i).Name
        Call SetHiddenAttribute(acForm, str, booHide)
    Next



    For i = 0 To db.Containers("Reports").Documents.Count - 1
        str = db.Containers("Reports").Documents(i).Name
        Call SetHiddenAttribute(acReport, str, booHide)
    Next i


    For i = 0 To db.Containers("Modules").Documents.Count - 1
        str = db.Containers("Modules").Documents(i).Name
        Call SetHiddenAttribute(acModule, str, booHide)
    Next i



    For i = 0 To db.Containers("Scripts").Documents.Count - 1
        str = db.Containers("Scripts").Documents(i).Name
        Call SetHiddenAttribute(acMacro, str, booHide)
    Next i

    Set db = Nothing

End Sub


Trovato qui.



Boso's version:
- aggiunto un po' di `print`
- il parametro booHide è `TRUE` di default

Public Sub HideObjects(Optional booHide As Boolean = False)
    
    'Created by Speakers_86
    'You are free to use, modify, and distribute
    'this as long as you leave this comment
    '
    'Purpose:   loops through all of you access objects, and
    '           hides them, the same as using the Access Gui to
    '           hide an object
    'Argument:  booHide
    '           an optional argument.  True hides objects,
    '           false unhides objects
    

    Dim db As Database
    Dim tbl As TableDef
    Dim qry As QueryDef
    Dim str As String
    Dim i As Integer
    
    On Error Resume Next
    
    Set db = CurrentDb()

    Debug.Print
    Debug.Print "**** TABLES"
    
    For Each tbl In db.TableDefs
        str = tbl.Name
        Debug.Print str
        Call SetHiddenAttribute(acTable, str, booHide)
    Next tbl


    Debug.Print
    Debug.Print "**** QUERIES"
    
    For Each qry In db.QueryDefs
        str = qry.Name
        Debug.Print str
        Call SetHiddenAttribute(acQuery, str, booHide)
    Next qry


    Debug.Print
    Debug.Print "**** FORMS"
    
    For i = 0 To db.Containers("Forms").Documents.Count - 1
        str = db.Containers("Forms").Documents(i).Name
        Debug.Print str
        Call SetHiddenAttribute(acForm, str, booHide)
    Next


    Debug.Print
    Debug.Print "**** REPORTS"
    
    For i = 0 To db.Containers("Reports").Documents.Count - 1
        str = db.Containers("Reports").Documents(i).Name
        Debug.Print str
        Call SetHiddenAttribute(acReport, str, booHide)
    Next i

    
    Debug.Print
    Debug.Print "**** MODULES"
    
    For i = 0 To db.Containers("Modules").Documents.Count - 1
        str = db.Containers("Modules").Documents(i).Name
        Debug.Print str
        Call SetHiddenAttribute(acModule, str, booHide)
    Next i


    Debug.Print
    Debug.Print "**** SCRIPTS"

    For i = 0 To db.Containers("Scripts").Documents.Count - 1
        str = db.Containers("Scripts").Documents(i).Name
        Debug.Print str
        Call SetHiddenAttribute(acMacro, str, booHide)
    Next i

    Set db = Nothing
    
    Debug.Print
    Debug.Print "**** END"

End Sub



Boso's version 2 - fatta da zero:

Public Sub ut_NascondiTuttiGliOggetti(Optional hidden As Boolean = True)
    
    Dim ob As Variant
    Dim name As String
    
    
    Debug.Print
    Debug.Print "**** Tables"
    
    For Each ob In CurrentData.AllTables
        name = ob.name
        Debug.Print name
        If Not LCase(name) Like "msys*" Then
            Application.SetHiddenAttribute acTable, name, fhidden:=hidden
        End If
    Next
    
    
    Debug.Print
    Debug.Print "**** Forms"
    
    For Each ob In CurrentProject.AllForms
        name = ob.name
        Debug.Print name
        Application.SetHiddenAttribute acForm, name, fhidden:=hidden
    Next
    
    
    Debug.Print
    Debug.Print "**** Macros"
    
    For Each ob In CurrentProject.AllMacros
        name = ob.name
        Debug.Print name
        Application.SetHiddenAttribute acMacro, name, fhidden:=hidden
    Next
    
    
    Debug.Print
    Debug.Print "**** Modules"
    
    For Each ob In CurrentProject.AllModules
        name = ob.name
        Debug.Print name
        Application.SetHiddenAttribute acModule, name, fhidden:=hidden
    Next
    
    
    Debug.Print
    Debug.Print "**** Reports"
    
    For Each ob In CurrentProject.AllReports
        name = ob.name
        Debug.Print name
        Application.SetHiddenAttribute acReport, name, fhidden:=hidden
    Next
    
    
    Debug.Print
    Debug.Print "**** Querys"
    
    For Each ob In CurrentData.AllQueries
        name = ob.name
        Debug.Print name
        Application.SetHiddenAttribute acQuery, name, fhidden:=hidden
    Next
    
    
    Debug.Print
    Debug.Print "**** DONE ****"
    
End Sub

17 June 2013

Send rendered control in Mail

Ritorna l'HTML dei controlli renderizzati
    Private Function getBody() As String

        Dim mSw As New IO.StringWriter()
        Dim mHtw As New HtmlTextWriter(mSw)
        Me.nome_del_controllo_server.RenderControl(mHtw)
        Return mSw.GetStringBuilder.ToString

    End Function

Bisogna aggiungere anche questa sub: serve per far funzionare la Function getBody()
    Public Overrides Sub VerifyRenderingInServerForm(ByVal control As System.Web.UI.Control)

        ' Confirms that an HtmlForm control is rendered for the specified ASP.NET server control at run time.

    End Sub

Trovato qui.