|
-
Feb 2nd, 2005, 10:33 AM
#1
Copy a form
If I want to add a new form to my project and want to make it very similar to an existing one, i.e. same properties and layout except for a few controls or details, what would be the best/fastest way to go about? Can I store forms as templates for future use?
Last edited by krtxmrtz; Feb 2nd, 2005 at 12:22 PM.
Lottery is a tax on people who are bad at maths
If only mosquitoes sucked fat instead of blood...
To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)
-
Feb 2nd, 2005, 11:00 AM
#2
Re: Copy a form
 Originally Posted by krtxmrtz
If I want to add a new form to my project and want to make it very similar to an existing one, i.e. same properties and layout except for a few controls or details, what would be the best/fastest way to go about? Can I store forms as templates for future use?
Copy the .FRM file at the WINDOWS level - to the new filename you want. Do not do this when you are in the project - so make sure you are out of the project.
Also copy the .FRX file is there is one - that file stores odd binary stuff about a form.
Then use NOTEPAD to EDIT the .FRM file. You will find only two or three references to the old FORMNAME in that .FRM file - it's just a simple text file - so change those references to the new name you choose.
Now go into VB - back into the project and ADD A NEW FORM - and you will see this new form available to choose from - add it and you are done.
-
Feb 2nd, 2005, 11:10 AM
#3
Re: Copy a form
What I would do is create many instances of exactly the same form:
Code:
Private Sub cmdCreateNewForm_Click()
Dim frmNew As frmJob
Set frmNew = New frmJob
Load frmNew
frmNew.Show
Set frmNew = Nothing
End Sub
Each time you click the button a new instance of the form is created and displayed.
Now what you can do is add a property or function to your form to set what type of form it is:
Code:
'In a module
Public Const FRM_TYPE_SALES As Long = 1
Public Const FRM_TYPE_ORDERS As Long = 2
'in the form
Public Sub SetFormType(ByVal plngType As Long)
Select Case plngType
Case FRM_TYPE_SALES
txtSalesAmount.Visible = True
Case FRM_TYPE_ORDERS
txtOrderNumber.Visible = True
End Select
End Sub
This code hides and shows a few controls on the form.
The rest of the controls you can leave as they will be used for both styles of form.
The code to call this now would be:
Code:
Private Sub ShowNewForm(ByVal plngType As Long()
Dim frmNew As frmJob
Set frmNew = New frmJob
Load frmNew
frmNew.SetFormType plngType
frmNew.Show
Set frmNew = Nothing
End Sub
This would be called using:
Code:
ShowNewForm FRM_TYPE_SALES
ShowNewForm FRM_TYPE_ORDERS
ShowNewForm FRM_TYPE_SALES
Does that make sense?
Woka
-
Feb 2nd, 2005, 12:19 PM
#4
Re: Copy a form
 Originally Posted by szlamany
Copy the .FRM file at the WINDOWS level - to the new filename you want...
That's more or less what I was afraid I'd have to do. Not that it means much trouble really, but I wanted to make sure there wasn't some tool in the developing environment to do it more directly, like when you copy a file in windows and it's exactly the same except the name.
Lottery is a tax on people who are bad at maths
If only mosquitoes sucked fat instead of blood...
To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)
-
Feb 2nd, 2005, 12:22 PM
#5
Re: Copy a form
 Originally Posted by Wokawidget
What I would do is create many instances of exactly the same form...
I save your code for future reference, though for now Szlamany's suggestion looks simpler.
Lottery is a tax on people who are bad at maths
If only mosquitoes sucked fat instead of blood...
To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)
-
Feb 2nd, 2005, 12:29 PM
#6
Re: Copy a form
Having 2 instances of the form in a project, that do almost exactly the same thing is madness 
More coding if one thing changes, or if there's a bug etc.
Alternatively you could create a usercontrol that had the common controls in it, and drop that onto 2 different forms, then just add the custom controls to that.
woka
-
Feb 2nd, 2005, 01:30 PM
#7
Re: Copy a form
 Originally Posted by krtxmrtz
I save your code for future reference, though for now Szlamany's suggestion looks simpler.
It might but you should look toward creating forms/controls dynamically and having only few created in design. You may also have a plain form with feew basic controls such button, textbox, label, etc (or without any at all) and control your form's load from some config table. This takes a bit to develop logic but once you're done - the rest is a breeze. And after all you may end up with excutable size of under a 1 MB ...
-
Feb 2nd, 2005, 02:28 PM
#8
Re: Copy a form
 Originally Posted by Wokawidget
Having 2 instances of the form in a project, that do almost exactly the same thing is madness 
More coding if one thing changes, or if there's a bug etc.
The thing is those forms are not exactly the same, only at the beginning. The code wouldn't be the same. For example, somtimes I want to have a number of forms without the control box at the upper right corner. As this is not the default setting when you create a new form, I'd rather "make copies" of the original form where there's no control box. Oh boy, it's not that easy to explain, but thank you guys for your suggestions. I'm sure sooner or later I'll have to seriously consider Rhinobulls advice and stop programming recklessly.
Lottery is a tax on people who are bad at maths
If only mosquitoes sucked fat instead of blood...
To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)
-
Feb 3rd, 2005, 03:42 AM
#9
Re: Copy a form
 Originally Posted by RhinoBull
It might but you should look toward creating forms/controls dynamically and having only few created in design. You may also have a plain form with feew basic controls such button, textbox, label, etc (or without any at all) and control your form's load from some config table. This takes a bit to develop logic but once you're done - the rest is a breeze. And after all you may end up with excutable size of under a 1 MB ...
Morning. Have you got an example of this code?
WOka
-
Feb 3rd, 2005, 08:28 AM
#10
Re: Copy a form
Morning man.
Not sample but the whole project and it's huge too. Let me see if I can scrap something from it. Will PM you when ready.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|