Solved

Copy/Delete Forms with VBA

Posted on 2011-09-05
2
193 Views
Last Modified: 2012-05-12
Hi Experts,

Within Access, using VBA, i'm wondering if I can do the following procedure:

If frmTwo exists then
   delete frmTwo
End if
copy fromOne to frmTwo

What i'm trying to do is, first to delete any older versions of form Two, then make a copy of form One and name it form Two.

thanks.
0
Comment
Question by:APD_Toronto
2 Comments
 
LVL 119

Accepted Solution

by:
Rey Obrero earned 500 total points
Comment Utility

if dcount("*","msysobjects","[name]='frmTwo'") > 0 then
  docmd.deleteobject acform, "frmTwo"
end if
 
  'copy frmOne

  docmd.CopyObject ,"frmtwo",acForm,"frmOne"
0
 
LVL 10

Expert Comment

by:LukeChung-FMS
Comment Utility
This code deletes the form or triggers an error if the form doesn't exist (we don't care since it's already gone). There could be situations where the form is opened or corrupt and can't be deleted where you should test for the error code after the deletion but for simplicity, I haven't included it.

On Error Resume Next
  DoCmd.DeleteObject acForm, "frmTwo"
On Error GoTo 0

DoCmd.CopyObject "frmTwo", acForm, "frmOne"

VBA code like this is part of our Total Visual SourceBook code library. It's in our Managing Microsoft Access Objects module.
http://www.fmsinc.com/MicrosoftAccess/modules/code/Access_Objects_modManagingObjects.htm

Hope this helps.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now