• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 254
  • Last Modified:

Create a duplicate form in VB 6

Hi,

I have a form called frmSched.

The form is loaded and i want a copy of the same form so i use this code.

Dim f as frmSched
set f = new frmSched.

How can i...
1) only ever allow two instances of the form to be opended ie  the original and the one created with the code above (at the moment i can click 4 times to get 4 copies)

2) Can i change the forms caption, so that i can have the first one with its original caption "Sheduler"  and have the second read "Sheduler 2"

Hope this makes sense.
0
sublimation
Asked:
sublimation
  • 2
  • 2
  • 2
  • +1
2 Solutions
 
sublimationAuthor Commented:
Hi,

I have a form called frmSched.

The form is loaded and i want a copy of the same form so i use this code.

Dim f as frmSched
set f = new frmSched.
f.show

How can i...
1) only ever allow two instances of the form to be opended ie  the original and the one created with the code above (at the moment i can click 4 times to get 4 copies)

2) Can i change the forms caption, so that i can have the first one with its original caption "Sheduler"  and have the second read "Sheduler 2"

Hope this makes sense.
0
 
PePiCommented:
2)
set f = new frmSched.
f.Caption = "Scheduler 2"
f.show

still thinking about Q1...
0
 
PePiCommented:
1)

Create a global variable gInstances as Integer

on the load_form event

gInstances = gInstances + 1


on the Unload event of the form

gInstances = gInstances - 1

I assume you use a button to launch the 2nd instance of the form? If so:

Click event of the button

if gInstance < 2 then
    Dim f as frmSched
    f.Caption = "Scheduler 2"
    f.Show
end if



0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
rettiseertCommented:
   'Count frmSched forms opened
    Dim frmSchedCount As Long, frm As Form
    For Each Form In Forms
        If TypeOf Form Is frmSched Then frmSchedCount = frmSchedCount + 1
    Next
   
    If frmSchedCount < 2 Then
        Dim f As frmSched
        Set f = New frmSched
        If frmSchedCount = 1 Then f.Caption = "Sheduler 2"
        f.Show
    End If
0
 
rettiseertCommented:
Sorry, this is the correct code, this way you dont have to use gobla variables:

Private Sub Command1_Click()

    'Count frmSched forms opened
    Dim frmSchedCount As Long, frm As Form
    For Each frm In Forms
        If TypeOf frm Is frmSched Then frmSchedCount = frmSchedCount + 1
    Next
   
    If frmSchedCount < 2 Then
        Dim f As frmSched
        Set f = New frmSched
        If frmSchedCount = 1 Then f.Caption = "Sheduler 2"
        f.Show
    End If

End Sub
0
 
tonym001Commented:
You could use classes but rettisert seems to have provided the easiest solution
0
 
sublimationAuthor Commented:
Thanks guys, ill give most points to Pepi, as it was Pepi's answer that I used and that got me underway.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now