Solved Change name of Form instance in tabs (1 Viewer)

Saphirah

Active member
Local time
Today, 21:09
Joined
Apr 5, 2020
Messages
163
Hello everyone.

I have a database with a form called frm_Auftrag.
After pressing a button i am creating a new Form instance of frm_Auftrag using this code:

ASP.net:
'Creates new Form instance
Dim f As New Form_frm_Auftrag

'Module Collection to store the form, else the form will be destroyed once the function ends
childrenForm.Add f

f.Visible = True

This, looks like the following:
I am using the option to show form tabs, so you can see all opened forms here.
1599131991219.png


Sadly, when i have 4-5 instances of frm_Auftrag you can not tell which form is which. That's why i wanted to change the display name of the form in the tab bar to something like
frm_Auftrag - 0056 or frm_Auftrag - 0043 etc...

I tried changing the "name" property of the form but this one is read only. Is there any other way to rename a form instance in access vba?
 

CJ_London

Super Moderator
Staff member
Local time
Today, 20:09
Joined
Feb 19, 2013
Messages
16,600
does this do what you require?

So far as I am aware, it is not possible to change the tab caption - but you could change the caption for a label on the form instance
 

theDBguy

I’m here to help
Staff member
Local time
Today, 12:09
Joined
Oct 29, 2018
Messages
21,447
Hi. I agree with CJ. Instead of the Name, try changing the Caption property of the Form.
 

neuroman9999

Member
Local time
Today, 14:09
Joined
Aug 17, 2020
Messages
827
even the 2 gentlemen who have answered already have given solutions, what I would ask is:: why are you even doing this? I have never seen a situation in 20 years of using this program where someone has done this, or even have had a need to.
 

CJ_London

Super Moderator
Staff member
Local time
Today, 20:09
Joined
Feb 19, 2013
Messages
16,600
why do you want multiple instances? For me plenty of reasons although I don't use tabbed documents, I use popup forms (where you can change the description in the window title bar). Simple example, 'I want to compare 2/3/4 people/products/companies/account transactions/whatever side by side'.

edit: Actually, using popups might be a workable solution for the OP. So thanks for making me think about it a bit more
 

Saphirah

Active member
Local time
Today, 21:09
Joined
Apr 5, 2020
Messages
163
Hey. Thank you for your response. I already have a caption on the form to differenciate different tasks from each other. I guess changing the tab label is impossible then :)

For neuromans post: My boss wants to be able to open multiple tasks at a time, and then switch between them. And what the boss says is law ^^
And i thought it would be a good challenge, because it is something new to learn :)
I am doing some access programming for personal reasons too, where i use multiple forms, and it would be cool to rename em for better view.
So yeah... ^^
 

neuroman9999

Member
Local time
Today, 14:09
Joined
Aug 17, 2020
Messages
827
Hey. Thank you for your response. I already have a caption on the form to differenciate different tasks from each other. I guess changing the tab label is impossible then :)

For neuromans post: My boss wants to be able to open multiple tasks at a time, and then switch between them. And what the boss says is law ^^
well actually that's a good statement however the only official laws are implemented by congress not your boss LOL :)

And if you want to do multiple tasks at one time or anything else in the form of multiple whatever at the same time you really should be using tabs on a single form for that purpose and not multiple forms and the reason why is because number one, Access is highly notorious for corruption if you do various things and more than likely this would be one of them that would cause it and you wouldn't know until you started doing it. And secondly, if this is a networked application in more than what you is using it then obviously record locks or table locks or any other kind of lock is going to play a huge part in this process and if you've got multiple instances of the same form open then that just creates unrecognizable have it for anyone and everyone and you'll be basically splitting hairs or pulling your hair out on that one
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 14:09
Joined
Feb 28, 2001
Messages
27,128
I'm thinking you cannot change the name of the form. However, a property on a form is hWnd, the window handle. I'm not even sure how you would go about it, but perhaps you could identify the window in which the form appears. It is a child window of the main Access window so I don't know if this will work quite the same but you could try to muck about with the child window caption through its hWnd handle.


However, there is another solution that depends on timing. This will only work when the form is currently the active window.


They look at the window rather than the form. As an experiment, you might try diddling around with ActiveWindow.Caption, which would let you pick a name based on content of the form. No guarantees on how far this will go because we are dealing with CHILD windows and I'm not sure as to whether this would apply to child windows or only to the parent window. Still, it is easy enough to try.
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 14:09
Joined
Feb 28, 2001
Messages
27,128
Adam's post was a bit confusingly worded. However, he is correct that opening the same form multiple times in the same application is a recipe for serious locking problems. That activity could lead to what is called a "deadlock" - where each child form holds resources needed but not available for the other child form to proceed. This is also called a "deadly embrace" because when it happens, the only way out is to kill one of the participant child forms, thus losing any changes made to the chosen "victim."

You might try my suggestions about window titles (captions) - but you might also want to be on the lookout for the possibility of deadly embraces. For what it is worth, this condition would not be limited to Access databases. I've seen it happen in a system based on an ORACLE back end even with record locking set relatively low.
 

neuroman9999

Member
Local time
Today, 14:09
Joined
Aug 17, 2020
Messages
827
Richard,

Almost every piece of visual basic code that uses a window API call has this handle in it I'm sure you know that good call.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 12:09
Joined
Oct 29, 2018
Messages
21,447
Hey. Thank you for your response. I already have a caption on the form to differenciate different tasks from each other. I guess changing the tab label is impossible then
Hi. I don't think so. In this book, Professional Access 2013 Programming, in Chapter 17 (pg 660), I wrote about "Multiple Instances of a Form" with sample code. I just tried it and modified the Caption property of the Form, and here's what I got.

1599147711766.png


Please notice the different names in the form Tabs. Before I changed the Caption property, all of them said "About." It wasn't a problem before because the code was originally used on a Popup Form. So, I think what you want is very possible.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 12:09
Joined
Oct 29, 2018
Messages
21,447
Hi. I don't think so. In this book, Professional Access 2013 Programming, in Chapter 17 (pg 660), I wrote about "Multiple Instances of a Form" with sample code. I just tried it and modified the Caption property of the Form, and here's what I got.

View attachment 84738

Please notice the different names in the form Tabs. Before I changed the Caption property, all of them said "About." It wasn't a problem before because the code was originally used on a Popup Form. So, I think what you want is very possible.
Just FYI... I switched it back to use Popup Forms, and it still worked!

1599149273955.png
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 15:09
Joined
May 21, 2018
Messages
8,519
I concur with everything @theDBguy said. This is definitely doable, and have done it any times. You can change the caption, but each instance shares the same name and that is not changeable. I know of no issues in access. doing this Obviously you probably want to keep the number of connections reasonable.

However, he is correct that opening the same form multiple times in the same application is a recipe for serious locking problems.
Do you have any experience with this being a problem in access? Never seen any issues.

However doing this as a tabbed form really gets you nothing. You cannot compare them side by side. As CJ said only makes sense as not modal pop ups so you can look at two records at once. If you are flipping between records, a far nicer interface would be to put the form into a subform and have a means to switch quickly between records. I see no value in multi tabbed instances, seems cluttered and slow.
 

CJ_London

Super Moderator
Staff member
Local time
Today, 20:09
Joined
Feb 19, 2013
Messages
16,600
I've been using the technique for nearly 20 years without any problems although typically in the types of apps I've built there would only be a need for a maximum of 3 or 4 instances. I agree coding has to be done carefully - but you quickly learn if there are any issues. Basically the form has to be self contained and 'end of line' i.e. no option to open another form or reference UDF's or other class modules.
 

Cronk

Registered User.
Local time
Tomorrow, 05:09
Joined
Jul 4, 2013
Messages
2,771
I've used multiple instances of a form in situations where the user is working on one record, and either gets a query on another record or needs to work on two or more records in parallel. Use hWnd to maintain the forms collection, but after changing the forms' captions to something meaningful, the caption can be used to reference the forms.
 

Users who are viewing this thread

Top Bottom