Solved

Copy/Delete Forms with VBA

Posted on 2011-09-05
2
201 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

624 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