Set name of new Multi innstance of form

D

Danny

I Have the following code for a command button to open up multiple instances
of a form

Does any one know how I can set the name of the new multiple insatnce of the
form .

Thanks
Danny

Function OpenAEntityForm()
Dim frm As Form
Set frm = New [Form_Entity Form]
frm.Visible = True
frm.Caption = frm.Hwnd & ", opened " & Now()
clnClient.Add Item:=frm, Key:=CStr(frm.Hwnd)
Set frm = Nothing
End Function

Function CloseAllClients()
'Purpose: Close all instances in the clnClient collection.
'Note: Leaves the copy opened directly from database window.
Dim lngKt As Long
Dim lngI As Long

lngKt = clnClient.Count
For lngI = 1 To lngKt
clnClient.Remove 1
Next
End Function
 
D

Dirk Goldgar

Danny said:
I Have the following code for a command button to open up multiple
instances of a form

Does any one know how I can set the name of the new multiple insatnce
of the form .

TTBOMK, you cannot change the Name property of the form instance. You
can change its Caption, but I see you're already doing that, as well as
specifying a unique key for that instance when you add it to your
collection. I don't see the value in trying to change the form's name,
anyway, so what is it you really want to do, and why?
 
D

Danny

Hi Dirk

I did not write the code for the multi instance form - I would like to have
the Caption changed to something more meaning full to the user -i.e. may be
one of the filed's in the form it self or Just to say that it is a 1st or 2nd
copy of the Entity form. I would like like to know if it is poss to limit the
number of multi instances to say 3.

Thanks
Danny
 
D

Dirk Goldgar

Danny said:
Hi Dirk

I did not write the code for the multi instance form - I would like
to have the Caption changed to something more meaning full to the
user -i.e. may be one of the filed's in the form it self or Just to
say that it is a 1st or 2nd copy of the Entity form. I would like
like to know if it is poss to limit the number of multi instances to
say 3.

In the code you posted, this line:
frm.Caption = frm.Hwnd & ", opened " & Now()

sets the caption. I don't know enough about these multiple instances to
know what information from the form itself might be used for the
caption, but you should be able to set it to something like "Copy 1 of
Entity Form" by replacing the above line with this:

frm.Caption = "Copy " & clnClient.Count + 1 & " of Entity Form"

If you don't want to allow more than 3 instances of the form, then test
clnClient.Count to see how many are already in there before you open a
new one. Either do that before calling OpenAEntityForm(), like this:

'----- start of code example 1 -----
If clnClient.Count < 3 Then
OpenAEntityForm
Else
MsgBox "Sorry, you're not allowed to open any more " & _
"copies of this form."
End If
'----- end of code example 1 -----

Or else apply the limit in the function itself:

'----- start of code example 2 -----
Function OpenAEntityForm()

Dim frm As Form

If clnClient.Count < 3 Then
Set frm = New [Form_Entity Form]
frm.Visible = True
frm.Caption = _
"Copy " & clnClient.Count + 1 & " of Entity Form"
clnClient.Add Item:=frm, Key:=CStr(frm.Hwnd)
Set frm = Nothing
Else
MsgBox "Sorry, you're not allowed to open any more " & _
"copies of this form."
End If

End Function
'----- end of code example 2 -----
 
D

Danny

Hi Dirck

that wored wonders, I used option 2
Thanks for your help really appreciated

Regards
Danny


Dirk Goldgar said:
Danny said:
Hi Dirk

I did not write the code for the multi instance form - I would like
to have the Caption changed to something more meaning full to the
user -i.e. may be one of the filed's in the form it self or Just to
say that it is a 1st or 2nd copy of the Entity form. I would like
like to know if it is poss to limit the number of multi instances to
say 3.

In the code you posted, this line:
frm.Caption = frm.Hwnd & ", opened " & Now()

sets the caption. I don't know enough about these multiple instances to
know what information from the form itself might be used for the
caption, but you should be able to set it to something like "Copy 1 of
Entity Form" by replacing the above line with this:

frm.Caption = "Copy " & clnClient.Count + 1 & " of Entity Form"

If you don't want to allow more than 3 instances of the form, then test
clnClient.Count to see how many are already in there before you open a
new one. Either do that before calling OpenAEntityForm(), like this:

'----- start of code example 1 -----
If clnClient.Count < 3 Then
OpenAEntityForm
Else
MsgBox "Sorry, you're not allowed to open any more " & _
"copies of this form."
End If
'----- end of code example 1 -----

Or else apply the limit in the function itself:

'----- start of code example 2 -----
Function OpenAEntityForm()

Dim frm As Form

If clnClient.Count < 3 Then
Set frm = New [Form_Entity Form]
frm.Visible = True
frm.Caption = _
"Copy " & clnClient.Count + 1 & " of Entity Form"
clnClient.Add Item:=frm, Key:=CStr(frm.Hwnd)
Set frm = Nothing
Else
MsgBox "Sorry, you're not allowed to open any more " & _
"copies of this form."
End If

End Function
'----- end of code example 2 -----

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 
D

Danny

Hi Dirck

When I close out the original form and try to go back into the main form - I
get the message which is testing the max number of Instances open, seems that
the close code it not right any suggestions

Function OpenAEntityForm()
Dim frm As Form
If clnClient.Count < 3 Then
Set frm = New [Form_Legal Entity Form]
frm.Visible = True
frm.Caption = frm.Name & ", opened " & Now()
'frm.Caption = frm.Name & ", opened " & Now()
'frm.Caption = frm.Hwnd & ", opened " & Now()
clnClient.Add Item:=frm, Key:=CStr(frm.Hwnd)
'frm.Caption = [Form_Legal Entity Form].[LEGAL NAME] & " Opened " & Now()
Set frm = Nothing
Else
MsgBox Err.Description & "Sorry you are not allowed to open any " &
"more Companies, Limit set to 4 "

End If
End Function


Function CloseAllClients()
'Purpose: Close all instances in the clnClient collection.
'Note: Leaves the copy opened directly from database window.
Dim lngKt As Long
Dim lngI As Long

lngKt = clnClient.Count
For lngI = 1 To lngKt
clnClient.Remove 1
Next
End Function

Thanks
Danny





Danny said:
Hi Dirck

that wored wonders, I used option 2
Thanks for your help really appreciated

Regards
Danny


Dirk Goldgar said:
Danny said:
Hi Dirk

I did not write the code for the multi instance form - I would like
to have the Caption changed to something more meaning full to the
user -i.e. may be one of the filed's in the form it self or Just to
say that it is a 1st or 2nd copy of the Entity form. I would like
like to know if it is poss to limit the number of multi instances to
say 3.

In the code you posted, this line:
frm.Caption = frm.Hwnd & ", opened " & Now()

sets the caption. I don't know enough about these multiple instances to
know what information from the form itself might be used for the
caption, but you should be able to set it to something like "Copy 1 of
Entity Form" by replacing the above line with this:

frm.Caption = "Copy " & clnClient.Count + 1 & " of Entity Form"

If you don't want to allow more than 3 instances of the form, then test
clnClient.Count to see how many are already in there before you open a
new one. Either do that before calling OpenAEntityForm(), like this:

'----- start of code example 1 -----
If clnClient.Count < 3 Then
OpenAEntityForm
Else
MsgBox "Sorry, you're not allowed to open any more " & _
"copies of this form."
End If
'----- end of code example 1 -----

Or else apply the limit in the function itself:

'----- start of code example 2 -----
Function OpenAEntityForm()

Dim frm As Form

If clnClient.Count < 3 Then
Set frm = New [Form_Entity Form]
frm.Visible = True
frm.Caption = _
"Copy " & clnClient.Count + 1 & " of Entity Form"
clnClient.Add Item:=frm, Key:=CStr(frm.Hwnd)
Set frm = Nothing
Else
MsgBox "Sorry, you're not allowed to open any more " & _
"copies of this form."
End If

End Function
'----- end of code example 2 -----

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 
D

Dirk Goldgar

Danny said:
Hi Dirck

When I close out the original form and try to go back into the main
form - I get the message which is testing the max number of Instances
open, seems that the close code it not right any suggestions

Function OpenAEntityForm()
Dim frm As Form
If clnClient.Count < 3 Then
Set frm = New [Form_Legal Entity Form]
frm.Visible = True
frm.Caption = frm.Name & ", opened " & Now()
'frm.Caption = frm.Name & ", opened " & Now()
'frm.Caption = frm.Hwnd & ", opened " & Now()
clnClient.Add Item:=frm, Key:=CStr(frm.Hwnd)
'frm.Caption = [Form_Legal Entity Form].[LEGAL NAME] & " Opened "
& Now() Set frm = Nothing
Else
MsgBox Err.Description & "Sorry you are not allowed to open any "
& "more Companies, Limit set to 4 "

End If
End Function


Function CloseAllClients()
'Purpose: Close all instances in the clnClient collection.
'Note: Leaves the copy opened directly from database window.
Dim lngKt As Long
Dim lngI As Long

lngKt = clnClient.Count
For lngI = 1 To lngKt
clnClient.Remove 1
Next
End Function

Thanks
Danny

I don't think I know enough about what you're doing to answer this
question. What is the "main form"? What is the "original form"? How
are you using this code? Where are you calling OpenAEntityForm() from?
Please tell me more about the sequence of events that causes the error.
 
D

Danny

Hi Dirk

pls see response below.

Dirk Goldgar said:
Danny said:
Hi Dirck

When I close out the original form and try to go back into the main
form - I get the message which is testing the max number of Instances
open, seems that the close code it not right any suggestions

Function OpenAEntityForm()
Dim frm As Form
If clnClient.Count < 3 Then
Set frm = New [Form_Legal Entity Form]
frm.Visible = True
frm.Caption = frm.Name & ", opened " & Now()
'frm.Caption = frm.Name & ", opened " & Now()
'frm.Caption = frm.Hwnd & ", opened " & Now()
clnClient.Add Item:=frm, Key:=CStr(frm.Hwnd)
'frm.Caption = [Form_Legal Entity Form].[LEGAL NAME] & " Opened "
& Now() Set frm = Nothing
Else
MsgBox Err.Description & "Sorry you are not allowed to open any "
& "more Companies, Limit set to 4 "

End If
End Function


Function CloseAllClients()
'Purpose: Close all instances in the clnClient collection.
'Note: Leaves the copy opened directly from database window.
Dim lngKt As Long
Dim lngI As Long

lngKt = clnClient.Count
For lngI = 1 To lngKt
clnClient.Remove 1
Next
End Function

Thanks
Danny

I don't think I know enough about what you're doing to answer this
question. What is the "main form"? What is the "original form"? How
are you using this code? Where are you calling OpenAEntityForm() from?
Please tell me more about the sequence of events that causes the error.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)

On the main form apart from other command buttons , I have a como box, after selection and in the afterupdate event in the properties the command is runs a macro to open "Legal Entity From"

And on this legal entity form I have a command button that has the on click
set to

=OpenAEntityForm() - this is where the code code comes in.

clear as mud but thats the chain of events.

Danny
 
D

Dirk Goldgar

Danny said:
Hi Dirk

pls see response below.

Dirk Goldgar said:
Danny said:
Hi Dirck

When I close out the original form and try to go back into the main
form - I get the message which is testing the max number of
Instances open, seems that the close code it not right any
suggestions

Function OpenAEntityForm()
Dim frm As Form
If clnClient.Count < 3 Then
Set frm = New [Form_Legal Entity Form]
frm.Visible = True
frm.Caption = frm.Name & ", opened " & Now()
'frm.Caption = frm.Name & ", opened " & Now()
'frm.Caption = frm.Hwnd & ", opened " & Now()
clnClient.Add Item:=frm, Key:=CStr(frm.Hwnd)
'frm.Caption = [Form_Legal Entity Form].[LEGAL NAME] & " Opened
" & Now() Set frm = Nothing
Else
MsgBox Err.Description & "Sorry you are not allowed to open any
" & "more Companies, Limit set to 4 "

End If
End Function


Function CloseAllClients()
'Purpose: Close all instances in the clnClient collection.
'Note: Leaves the copy opened directly from database window.
Dim lngKt As Long
Dim lngI As Long

lngKt = clnClient.Count
For lngI = 1 To lngKt
clnClient.Remove 1
Next
End Function

Thanks
Danny

I don't think I know enough about what you're doing to answer this
question. What is the "main form"? What is the "original form"?
How
are you using this code? Where are you calling OpenAEntityForm()
from?
Please tell me more about the sequence of events that causes the
error.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)

On the main form apart from other command buttons , I have a como
box, after selection and in the afterupdate event in the properties
the command is runs a macro to open "Legal Entity From"

And on this legal entity form I have a command button that has the
on click set to

=OpenAEntityForm() - this is where the code code comes in.

clear as mud but thats the chain of events.

Danny

Danny, I'm having a hard time figuring this out. If you'd like to send
me a cut-down copy of your database, containing only the elements
necessary to demonstrate the problem, compacted and then zipped to less
than 1MB in size (preferably much smaller) -- I'll have a look at it,
time permitting. You can send it to the address derived by removing NO
SPAM from the reply address of this message. If that address isn't
obvious to you, you can get it from my web site, which is listed in my
sig.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top