Solved

Copy/Delete Forms with VBA

Posted on 2011-09-05
2
194 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
ID: 36486133

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:Luke Chung
ID: 36489632
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

895 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

14 Experts available now in Live!

Get 1:1 Help Now