VBA, MS Access MS Access в примерах

Изменение свойств всех форм приложения

Простенький перебор:

Private Sub AllFormsInApp()
Dim dbs As Database, ctr As Container, doc As Document
'--------------------------------------------------------------------
On Error GoTo AllFormsInApp_Err
    
    Set dbs = CurrentDb
    Set ctr = dbs.Containers!Forms
    'cycle through all forms
    For Each doc In ctr.Documents
        Debug.Print "Processing the form:" & doc.Name
     Next doc

AllFormsInApp_Bye:
    Set ctr = Nothing
    Set dbs = Nothing
    Exit Sub

AllFormsInApp_Err:
    MsgBox "Error " & Err.Number & vbCrLf & Err.Description & vbCrLf & _
    "in procedure AllFormsInApp", vbCritical, "Error!"
    Resume AllFormsInApp_Bye
End Sub


Вариации по теме:

Private Sub ChangeFormsPrp()
'es = 10.10.2001
'Изменение определенных (ниже) свойств сразу всех форм приложения
'--------------------------------------------------------------------
    Dim dbs As Database, ctr As Container, doc As Document
    Dim objForm As Form
'--------------------------------------------------------------------
On Error GoTo ChangeFormsPrp_Err
    
    Set dbs = CurrentDb
    Set ctr = dbs.Containers!Forms
    'цикл по всем формам
    For Each doc In ctr.Documents
        'открытие формы в режиме редакции и в скрытом режиме
        DoCmd.OpenForm doc.name, acDesign, "", "", , acHidden
        Set objForm = Forms(doc.name)
        
        'отображение инфы о тек. форме в Status Bar
        'SysCmd acSysCmdSetStatus, "Обрабатываю форму - " & doc.name
        
        Debug.Print "Обрабатываю форму - " & doc.name
            '======================================================
            'СОБСТВЕННО ИЗМЕНЕНИЕ СВОЙСТВ
            objForm.AutoCenter = True   'Свойство =Выравнивание по центру=
            'objForm.PopUp = True       'Свойство =Всплывающая форма=
            'objForm.Modal = True       'Свойство =Модальная форма=
            '...
            '... ДРУГИЕ свойства
        'Закрытие формы
        DoCmd.Close acForm, doc.name, acSaveYes
    Next doc
    'SysCmd (acSysCmdClearStatus)

ChangeFormsPrp_Bye:
    Set objForm = Nothing
    Set ctr = Nothing
    Set dbs = Nothing
    Exit Sub

ChangeFormsPrp_Err:
    'MsgBox  "При обработке формы - " & doc.name
    MsgBox "Error " & Err.Number & vbCrLf & Err.Description & vbCrLf & _
    "in procedure ChangeFormsPrp", vbCritical, "Error!"
    Resume ChangeFormsPrp_Bye
End Sub



Изменение свойств (Properties) указанной в аргументе формы

Public Sub Change_Form_Properties(sFormName As String)
'es - 09.01.2013
'Изменение свойств (Properties) указанной в аргументе формы
'--------------------------------------------------------------------
'Пишем в Immediate Window Например:
'   Change_Form_Properties "00OnStart" ' + [Enter]
'   И готово!
'--------------------------------------------------------------------
Dim objForm As Form, prp As Property
On Error GoTo Change_Form_Properties_Err
    DoCmd.OpenForm sFormName, acDesign, "", "", , acHidden
    Set objForm = Forms(sFormName)
    With objForm
    'Раздел FORMAT
        .AllowDatasheetView = False
        .AllowPivotTableView = False
        .AllowPivotChartView = False
        .AllowLayoutView = False
        .AutoCenter = True
        .RecordSelectors = False
        .NavigationButtons = False
        
        'ScrollBars
        '   Neither  0 No scroll bars appear on the form.
        '   Horizontal Only 1 Horizontal scroll bar appears on the form.
        '   Vertical Only 2 Vertical scroll bar appears on the form.
        '   Both 3 (Default) Vertical and horizontal scroll bars appear on the form.
        .ScrollBars = 0
        
        .ControlBox = True
        .CloseButton = True
        'Maximize and Minimize buttons
        '   None 0 The Maximize and Minimize buttons aren't visible.
        '   Min Enabled 1 Only the Minimize button is visible.
        '   Max Enabled 2 Only the Maximize button is visible.
        '   Both Enabled 3 (Default) Both the Minimize and Maximize buttons are visible.
        .MinMaxButtons = 0
    End With
    
   
    DoCmd.Close acForm, sFormName, acSaveYes
    DoCmd.OpenForm sFormName


Change_Form_Properties_Bye:
    On Error Resume Next
    Set prp = Nothing
    Set objForm = Nothing
    Exit Sub

Change_Form_Properties_Err:
    MsgBox "Error " & Err.Number & vbCrLf & Err.Description & vbCrLf & _
    "in procedure Change_Form_Properties", vbCritical, "Error!"
    Resume Change_Form_Properties_Bye
End Sub
Назад ToTop
L.E. 24.02.2022
Рейтинг@Mail.ru