Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Copy/Delete Forms with VBA

Posted on 2011-09-05
2
Medium Priority
?
207 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 2000 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
Windows Explorer let you handle zip folders nearly as any other folder: Copy, move, change, and delete, etc. In VBA you can also handle normal files and folders, but zip folders takes a little more - and that you'll find here.
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

916 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