[AccessD] Closing a Form using VBA

Darren D darren at activebilling.com.au
Wed May 14 08:15:53 CDT 2008


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"

Darren
-----------------

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


aaaah, Hi everyone.

I am sure this is dead simple, but I keep thinking in Excel.VBA rather than
Access.VBA so I get stuck. urrrgh.

On Form1 I have a button that opens Form2.  Once Form2 is open I want Form1 to
close itself and save any data that maybe there.

'------ Code Being Used --------------
Private Sub cmdTL_Click()
Call OpenTL_Form
DoCmd.Close  ' <-- Doing this closes the form just opened, and leaves me with
the original form.
End Sub
' ------- end code -----------------

The code above resides in the Form1 code module.
Ideally I would like to make Form1 a variable so this would work from any form.

'-------Aircode Start ----
Sub AirCode()

Dim sTHIS_FORM as string

sTHIS_FORM = ActiveForm.Name
Call OpenTL_Form
[Forms]![" & sTHIS_FORM & "].Close True 'Close and save data

End Sub
' ---- End Aircode ---------

Any Advice folks?

Regards
Darryl.

This email and any attachments may contain privileged and confidential
information and are intended for the named addressee only. If you have received
this e-mail in error, please notify the sender and delete this e-mail
immediately. Any confidentiality, privilege or copyright is not waived or lost
because this e-mail has been sent to you in error. It is your responsibility to
check this e-mail and any attachments for viruses.  No warranty is made that
this material is free from computer virus or any other defect or error.  Any
loss/damage incurred by using this material is not the sender's responsibility.
The sender's entire liability will be limited to resupplying the material.

-- 
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