Solved

Copy/Delete Forms with VBA

Posted on 2011-09-05
2
198 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 120

Accepted Solution

by:
Rey Obrero (Capricorn1) 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

749 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