AccesSoft - Articles - Interface
Main | Articles | Links | Map

Work with forms in Access

Else making first its large project, years so six back, I came to conclusion that on screen must be only one form. Several simultaneously opened forms clutter up the worker a field, appears the possibility of the casual switching between opened forms that can bring about mistake. (The Truth, sometimes presence several forms on screen justified. For instance, from big form you можешь to cause some reference book to look necessary importance or correct him(it).) Use the modal forms not always justified. For instance, at conclusion on screen of the report from modal form, this form remains on screen over report. That not much-that beautifully. It Happened to to sit for development of the interface. After several experiments, I came to conclusion that when call of one form from another, it is necessary to do the parental form invisible, but when closing - restore visibility. The Single condition - an issue in affiliated form of the name of the parental form. Here possible use three methods. (At least once, I додумался before three.)

  • Use global text variable. At moment of the opening of the form, read from it name of the parental form, place in local variable, but in global to write its name of the opened form. When calling the following form, the operation is repeated. Thereby, name of the current active form is kept in global variable. When closing the form first name of the parental form fits in global variable from local variable, is then closed current form and management is sent parental form.
  • Send the name of the parental form through arguments of the command DoCmd.OpenForm
  • Send the name of the parental form through тег (Tag) downloaded forms.

Each way has both their owns advantage, and defect. Finally, I have bored to draw the line of the code in each form, on this I have done two subroutines and stand;bear them in separate module.

Here is example to realization of control visibility forms at transmission of the name on the third method.

Subroutine of the opening of the form

Public Sub GotoForm(Name As String, Optional MyForm As Variant, Optional StrWhere As Variant, Optional StrArg As String)

On Error GoTo Err_GotoForm
Dim stDocName As String
Dim stLinkCriteria As String
Dim strHide As String


    strHide = Screen.ActiveForm.Name


    If Not IsMissing(StrWhere) Then
        If Len(StrWhere) > 0 Then
            DoCmd.OpenForm Name, acNormal, , StrWhere, , , StrArg


            If Not IsMissing(MyForm) Then
                DoCmd.Close acForm, strHide
            Else
                Screen.ActiveForm.Tag = strHide
            End If
            Exit Sub
        End If
    End If


    DoCmd.OpenForm Name, acNormal, , , , , StrArg

    If Not IsMissing(MyForm) Then
        DoCmd.Close acForm, strHide
    Else
        Screen.ActiveForm.Tag = strHide
    End If
Exit_GotoForm:
    Exit Sub
Err_GotoForm:
    MsgBox Err.Description
    Resume Exit_GotoForm
End Sub

****************************************************

Function of the closing the form

Public Function fnCloseForm() As Long

On Error GoTo Err_fnCloseForm
Dim strUnhide As String
Dim Name As String


    Name = Screen.ActiveForm.Name

    If Nz(Screen.ActiveForm.Tag) = "" Then
        DoCmd.Close acForm, Name
    Else
        strUnhide = Screen.ActiveForm.Tag
        DoCmd.Close acForm, Name
        DoCmd.SelectObject acForm, strUnhide
    End If


    fnCloseForm = 0
Exit_fnCloseForm:
    Exit Function
Err_fnCloseForm:


    fnCloseForm = Err.Number
    Resume Exit_fnCloseForm
End Function

These two subroutines it is necessary to use together. The Code certainly далек from ideal, for instance subroutine GotoForm possible to present in the manner of:

Public Sub GotoForm(Name As String, Optional MyForm As Variant, Optional StrWhere As String, Optional StrArg As String)

On Error GoTo Err_GotoForm
Dim stDocName As String
Dim strHide As String


    strHide = Screen.ActiveForm.Name

    Screen.ActiveForm.Visible = False

    DoCmd.OpenForm Name, acNormal, , StrWhere, , , StrArg

    If Not IsMissing(MyForm) Then
        DoCmd.Close acForm, strHide
    Else
        Screen.ActiveForm.Tag = strHide
    End If
Exit_GotoForm:
    Exit Sub
Err_GotoForm:
    MsgBox Err.Description
    Resume Exit_GotoForm
End Sub

Both variants runnable moreover the second more simply and красивее. We Ask not too to scold, I these подпрограммки сочинил, when from the whole literature on Access beside me was a book "Access 97 - a steps to efficient work" (something like "Access for 24 hours") and хелп to most Access 97.

These subroutines essentially are "cover" standard commands Access. Their possible change and дорабатывать under its taste. But also in such type they solve the majority costing problems before You. But if it is necessary, that add the new parameters. Skachati example to realization of the functioning(working) the forms You may below

Author: Joss Size: 44 kB It Is Added: 05.10.2007

Main | Articles | Links | Map
Шкаф-купе лагуна. Командоры сенаторы шкаф купе.

Copyright 2007 - 2008 AccesSoft. All Rights Reserved