[AccessD] Closing a Form using VBA

Edward S Zuris edzedz at comcast.net
Wed May 14 15:50:49 CDT 2008


 Here is an example where some VBA code opens
 a another form, runs some additional 'Public'
 VBA code from the newly opened form, then
 closes the calling form.

 = = = = = = = = = = = = = = = = = = = = = = = = =

Private Sub cmdJobModule_Click()

    Dim sTmp0               As String
    Dim zzForm              As Form

    sTmp0 = ""

    ' *******************************************************
    '  Open the New Form.
    '
    DoCmd.OpenForm "zJp700zJDBoss", , , sTmp0

    ' *******************************************************
    '  Call some VBA Public Code from the new Form.
    '  Reset the stop-go Indicators.
    '
    Set zzForm = [Forms]![zJp700zJDBoss]
    Call zzForm.cmdReset_Click
    Set zzForm = Nothing

    ' *******************************************************
    '  Call some VBA Public Code from the new Form.
    '  Check the stop-go Indicators.
    '
    Set zzForm = [Forms]![zJp700zJDBoss]
    Call zzForm.cmdCheckCheck_Click
    Set zzForm = Nothing

    beep

    ' *******************************************************
    '  Close the old Form.
    '
    DoCmd.Close 2, "frm060Admin"

End Sub


 = = = = = = = = = = = = = = = = = = = = = = = = =



-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com]On Behalf Of Steve Schapel
Sent: Wednesday, May 14, 2008 12:33 PM
To: Access Developers discussion and problem solving
Subject: Re: [AccessD] Closing a Form using VBA


Darren,

As mentioned in my earlier reply, the way to explicitly reference the
form from which the code is being called, as is the case with Darryl's
example, is:
DoCmd.Close acForm, Me.Name

Regards
Steve

Darren D wrote:
> Hi Darryl
>
> Explicitly name the form you wanna close or it will close the one in the
line
> above the close command
>
> EG
> Call OpenTL_Form
> DoCmd.Close  ' <-- Doing this closes the form just opened, and leaves me
with
> the original
>
> Will just close OpenTL_Form
>
>
> Needs to be
>
> Call OpenTL_Form
> DoCmd.Close acForm, "SomeCoolFormNamehere"
>
--
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com




More information about the AccessD mailing list