473,399 Members | 3,106 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Copying an existing form

Hi,

I'm trying to copy an existing form in the same database with a different name. For example, I'm copying the form "Aggregate" to a new name "Aggregate2"

I'm trying to do create the name of the new form dynamically, but checking to see if the form exists and then incrementing the number. I have done this and it works, but I get a type mismatch error when I try to copy the form.

My code looks like this:

Expand|Select|Wrap|Line Numbers
  1. Dim FormNum As Integer
  2. Dim FormStr As String
  3. Dim obj As AccessObject, dbs As Object
  4.  
  5. Set dbs = Application.CurrentProject
  6. FormNum = 2
  7. FormStr = "Aggregate" & FormNum
  8.  
  9. For Each obj In dbs.AllForms
  10.     If obj.Name = "" & FormStr & "" Then
  11.         FormNum = FormNum + 1
  12.         FormStr = "Aggregate" & FormNum
  13.     End If
  14. Next obj
  15.  
  16. DoCmd.CopyObject FormStr, acForm, "Aggregate"
Oct 13 '11 #1
3 2232
NeoPa
32,556 Expert Mod 16PB
You're passing the wrong parameter values to the CopyObject command on line #16. See Help for the correct values but the parameters are :
Expand|Select|Wrap|Line Numbers
  1. DoCmd.CopyObject(DestinationDatabaseNewNameSourceObjectTypeSourceObjectName)
Oct 14 '11 #2
ADezii
8,834 Expert 8TB
@NeoPa:
All Arguments to CopyObject() are Optional, the OP simply forgot the Placeholder for the 1st Argument (Destination Database).

@velvadp:
You should definately check and see if a Copy already exists, before attempting to Copy the Form. Notice also the Comma directly after CopyObject and the change in Syntax:
Expand|Select|Wrap|Line Numbers
  1. On Error Resume Next
  2. Dim FormNum As Integer
  3. Dim FormStr As String
  4. Dim obj As AccessObject
  5. Dim dbs As Object
  6.  
  7. Set dbs = Application.CurrentProject
  8.  
  9. FormStr = "Aggregate"
  10.  
  11. 'Delete the Copied Version if it exists
  12. DoCmd.DeleteObject acForm, FormStr & "2"
  13.  
  14. For Each obj In dbs.AllForms
  15.   If obj.Name = FormStr Then
  16.     DoCmd.CopyObject , FormStr & "2", acForm, FormStr
  17.       Exit For
  18.   End If
  19. Next obj
Oct 14 '11 #3
NeoPa
32,556 Expert Mod 16PB
Indeed they are ADezii, and that's an accurate reflection of the problem.

However, if I'd responded in that way it could be inferred I was advising the OP to add an extra parenthesis, whereas I was rather hoping he might take the more appropriate option of using Named Parameters. With Named Parameters for those procedure calls that aren't so obvious (such that one could get the positions wrong) you make it clear to any developer/reviewer what is going on and that makes it easier all around. It's also harder to get it wrong in the first place.
Oct 14 '11 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Tony D. | last post by:
I could really use some help with a problem I am having. I am trying to add a new field to an existing form that combines two tables into one form. In this same databse I have another form that...
9
by: Raposa Velha | last post by:
Any of you ever catch this bug: I made a form and decided to copy it. Then I modified the cloned form. Then I run it and access start saying "Error accessing file. Network connection may have been...
7
by: Andy Bates | last post by:
I have hopefully a simple problem in C#. I designed a form with a listview on left, vert splitter against that, then the remainder of the form from top to bottom: a listview, horiz splitter and...
1
by: Wrauberto | last post by:
Howdy, I have an existing form loaded with all sorts of pretty boxes and buttons. I want to make this an MDI child and need to create an MDI parent OR make this a parent and launch children from...
1
by: Bill Nguyen | last post by:
I need to copy the existing form EDIT1 to EDIT2 into the same project so that I can modify EDIT2 while preserving EDIT1 for a slightly different use. What's an easy way to do it? Thanks Bill
3
by: Son KwonNam | last post by:
Hello, When there a two forms like the follosings, <form name="source"> <input name="a..." value=".." ..> <input name="a..." value=".." ..> <input name="a..." value=".." ..> <input...
3
by: garyusenet | last post by:
Dear Professionals, I have recently been using the wonderful krypton toolkit and am trying to use them in my small hobby application. I include this bit of info as an aside really because i'm...
7
by: ewarts | last post by:
Hello all, I'm having an issue adding more combo box to an existing form, please correct me if I'm wrong in my method but i'm copying the combo box above and pasting it below so to have the same...
2
by: mhnaccess | last post by:
I am trying to create controls, EG a text box, at runtime. ALL examples I find are creating a new form at the same time. I want to create a control on an existing form. The following does not...
0
by: don.fleming | last post by:
Greetings, Forms programming not my specialty, appreciated any advice on my direction I'm going with this. Basic need my client has is to "clone" the existing 3 tables records being viewed on a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.