Creating new form from existing form (1 Viewer)

Dave E

Registered User.
Local time
Yesterday, 20:34
Joined
Sep 23, 2019
Messages
104
Hi all,

Does anybody know a way to create a new form and move all the objects and code from one form with all its parameters and make a copy in a new blank form?

I have an existing problem which appears to be only on the db's main form.

I have so far -
decompiled, recompiled, compressed and saved the db
I have exported and imported the data objects as text into a clean db (as advised in a previous thread)
I have checked all the code on the form (you would think that compiling/repairing would have found any problems though)

After some testing I have found that -
the problem doesn't seem to happen with any other form
the problem occurs mainly when switching from form view to design view though occasionally, on opening the database, the form looks good but none of the combos work at all.
I'm losing hair faster lately.

Is it possible that the form itself (not the objects or code) could be the source of the problem?
Is there a way to create a new form and copy all of the objects over to eliminate the Accesss Form base?

Thanks

DaveE
 

jdraw

Super Moderator
Staff member
Local time
Yesterday, 23:34
Joined
Jan 23, 2006
Messages
15,380
Is this a database that you could post for members to review?
 

LarryE

Active member
Local time
Yesterday, 20:34
Joined
Aug 18, 2021
Messages
592
Well since you didn't give anybody even a hint as to what is wrong or if error messages are produced or if they are produced, what they say, then no one has a clue as to how to help you find your solution. You mention "the problem" several times but give no clue as what it is.
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Yesterday, 22:34
Joined
Feb 28, 2001
Messages
27,209
You can create a blank form, open both the old and new forms, and then click inside the old form. On the ribbon there should be a SELECT ALL option, which will copy all of the controls. The right-click, select COPY, and then move to the new form, right-click, select PASTE.

This DOES NOT move code. However, you CAN open the VBA window on the OLD form and use the SELECT ALL, COPY, PASTE sequence there too. But note that event code will not be properly bound in that case.

As to your problem, I hope you are more forthcoming with your primary care physician than you were with us. Do you go to the doctor and say, "Doc, I don't feel good. Fix me." ?? Or do you give him enough symptoms to prevent him from suggesting amputation?
 

isladogs

MVP / VIP
Local time
Today, 04:34
Joined
Jan 14, 2017
Messages
18,246
Although you can select all code in the VBE, to the best of my knowledge there has never been a SELECT ALL ribbon item.
However, you can 'lasso' all objects, then click copy. Go to the new blank form and select Paste.

You can also export all code to a text file then reimport it to the new form
 

Pat Hartman

Super Moderator
Staff member
Local time
Yesterday, 23:34
Joined
Feb 19, 2002
Messages
43,328
Although you can copy a form using the GUI and paste it with a new name, this will likely also copy any corruption. The method to do it without disconnecting the code from the form but still getting rid of the likely corruption is by using SaveAsText and LoadFromText. I have an automated version of this code that exports ALL forms/reports/macros/queries/modules or imports them as part of a backup procedure. I implemented it a few years ago because I had a database that was persistent in becoming corrupted. I was never able to track down the source of the corruption but the db was so fragile that I ran code to export every object except tables whenever I closed the FE (the app tested to see that it was ME logged in rather than a user since there was no point in doing this for a user. They never made design changes). Then if I came in the next day and found that I couldn't open the FE, I could spend 5 minutes to recreate it from the text files.

Here's a hard-coded example that shows how to do it for only ONE form and then you can delete the old version. I close and compact at that point. Then open in design view and import the replacement. Then compact again. Just change the names to suit your situation.
Code:
Public Sub ExportForm()
Dim strPath As String
Dim strObjName As String
    strPath = "C:\Pat\Form_"
    strObjName = "frmCHIPAAExports"
    Application.SaveAsText acForm,  strObjName, strPath & strObjName & ".txt"
End Sub

Public Sub ImportForm()
Dim strPath As String
Dim strObjName As String
    strPath = "C:\Pat\Form_"
        strObjName = "frmCHIPAAExports"
    Application.Application.LoadFromText acForm, strObjName , strPath & strObjName  & ".txt"
End Sub
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 04:34
Joined
Jul 9, 2003
Messages
16,283
You can also export all code to a text file then reimport it to the new form
I was going to say I was talking to @Pat Hartman Wednesday, and I understand that "You can also export the form to text and then reimport it" .... But I see pat has already explained the method. .
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Yesterday, 22:34
Joined
Feb 28, 2001
Messages
27,209
Just a question: Is this line correct with a "double application" reference?

Code:
    Application.Application.LoadFromText acForm, strObjName , strPath & strObjName  & ".txt"
 

Pat Hartman

Super Moderator
Staff member
Local time
Yesterday, 23:34
Joined
Feb 19, 2002
Messages
43,328
Looks like a typo. Sorry. I copied and pasted parts of the code.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 11:34
Joined
May 7, 2009
Messages
19,247
better to Re-Create your form from scratch.
yes you can import and what are you importing?
you are importing also it's disease (covid?).
and when you re-export it back, the virus is intact.
 

Dave E

Registered User.
Local time
Yesterday, 20:34
Joined
Sep 23, 2019
Messages
104
Thanks for all your replies.

If you read my initial post I asked how to move all objects and code from one form to a new one. The rest of the post was an explanation of why I was looking do it.

I have tried all of the suggestions given thus far for my problem without success. Finding that the problem exists onl;y on the main form leads me to believe that the form base is somehow corrupted.
The form pattern isn't a part of my database, so changing the 'container' might solve the problem or at least be worth trying.

DaveE
 

MajP

You've got your good things, and you've got mine.
Local time
Yesterday, 23:34
Joined
May 21, 2018
Messages
8,547
I have tried all of the suggestions given thus far for my problem without success. Finding that the problem exists onl;y on the main form leads me to believe that the form base is somehow corrupted.
Did you really save and load from text into a clean db? That is guaranteed to remove corruption. If so then it is not a corrupted form.
 

Pat Hartman

Super Moderator
Staff member
Local time
Yesterday, 23:34
Joined
Feb 19, 2002
Messages
43,328
you are importing also it's disease (covid?).
The disease is in the p-code which we never see. Therefore, any method that copies the form without the p-code will solve the problem.

I have tried all of the suggestions given thus far for my problem without success.
So, you tried #7? Did you do both the mainform and the subform?

If you have a querydef bound to the form, recreate that. You can open the query in SQL view and copy the string. Paste it to notepad. Delete the querydef. compact. Create a new querydef, paste in the saved SQL string.
 

Dave E

Registered User.
Local time
Yesterday, 20:34
Joined
Sep 23, 2019
Messages
104
Did you really save and load from text into a clean db? That is guaranteed to remove corruption. If so then it is not a corrupted form.
Indeed, I did. I followed the methods set out in the other thread, along with several other methods found online.

The annoying thing is the randomness of the crashes. Sometimes it will and sometimes it won't crash. And there's nothing going on in VBA or queries at the time of clicking on the form's top banner to change to the Design View. I doubt it's a code error.

I will keep searching for a solution but if anyone has any other suggestions I will be grateful.

DaveE
 

isladogs

MVP / VIP
Local time
Today, 04:34
Joined
Jan 14, 2017
Messages
18,246
Have you ruled out that you may have a corrupted form control?
 

Dave E

Registered User.
Local time
Yesterday, 20:34
Joined
Sep 23, 2019
Messages
104
Still testing...
Exported and imported Text of subform to new form - no change.
 
Last edited:

Pat Hartman

Super Moderator
Staff member
Local time
Yesterday, 23:34
Joined
Feb 19, 2002
Messages
43,328
Exported and imported Text of subform to new form - no change.
Did you do it all in the same step and compact between the export and the import?
Did you export the SQL separately also?
 

Dave E

Registered User.
Local time
Yesterday, 20:34
Joined
Sep 23, 2019
Messages
104
How do you compact when the the it's a text file? I compacted before and after the process of changing the form. I didn't export the SQL separately. Wouldn't that have gone through the same process with the text?

DaveE
 

Users who are viewing this thread

Top Bottom