Borderless Forms but resizeable and with "x" button? Custom Titlebar? (1 Viewer)

lolgoodone

New member
Local time
Today, 06:26
Joined
Sep 15, 2020
Messages
4
Hello ^^

I have spent the better part of a week researching on this topic, and I am not sure whether there is a simple(r) way of doing this - if you can help me or show me my error of ways, I'd be glad :)

Background info:
I want to have a pop-up form, that behaves and looks like any normal window ever, with Min, Max, and Close ("x") buttons on the top right corner. However, when a user fills in some data via the form and decides to cancel the entry, they might be tempted to just use the "x" instead of the dedicated cancel button. This leaves a half finished entry in my DB. Sure, I could set the forms control box property to "false" or the form border to "none", but that would remove basic form behaviour like resizing, moving or min/maxing.

My question: Is there a way to retain all these features (min/maxing a form, moving and resizing it, closing the form with "x") in this standardised window layout (min, max, "x" on the top right corner) while at the same time making sure that a user just can't press "x" and close the form with a half finished entry?


My intention is to provide a clean, simple, and intuitive way of interacting with the form and its control box (the "intuitive" part being a major headache at times xD)
I had a few ideas in mind already:
  1. Checking if all necessary fields are filled and only then allowing to close the form, with proper error handling to catch the messages popping up when pressing "x"
  2. Trapping if a user presses on "x" (prematurely) and running through the cancel routine before closing the record/form
  3. Creating a custom form title bar and recreating the functions of min, max and "x" manually
  4. Training all users to use the "cancel" button instead
  5. Swiching the Control Box property of the form dynamically with VBA
However, these ideas weren't all that clean either:
  1. I have some necessary fields already that must be filled out, while other fields are optional. This might be the easiest to implement, but constant error messages when trying to close the form seem not that user fiendly. (While writing this I figured, I could call the cancel procedure in the error handler, not sure if that will work?)
  2. There seems to be no way to handle the "x" button being pressed. Other than possibly on the event "On Close", but that didn't work (unless I did smth wrong).
  3. There is no non-API way to hide the form title bar (is there?), so creating your own title bar with custom buttons looks rather bad and confusing too. Either you have to pick a double-height title bar, or you cannot move/resize the form when disabling the native titlebar because of the borderstyle ("none", "thin").
    However, I found quite some solutions with APIs and butchered one together on my own, but there is still some buggy behaviour that I have no idea how to handle/fix.
  4. I'll do that, but this seems to be very prone for errors still.
  5. Doesn't work, as it can be only set in Design View afaik.

To add to point 3, I'll attach a small sample DB as well, where I smashed together some APIs and it works sort of, but not relieably, and it would need quite some work to behave like the standard control box on a form. How to fix those errors would be a seperate question though...

Maybe I'm overlooking some simple solution, but right now I can't see the forrest with all those trees in the way :p
Thanks in advance ^^
 

Attachments

  • testCustomTitlebar.zip
    74.5 KB · Views: 289

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 05:26
Joined
Jul 9, 2003
Messages
16,271
Yes, the Form has an "on close" event, the code will run when the form closes. You could put what you want to happen when it closes in there.
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 21:26
Joined
Oct 29, 2018
Messages
21,449
Hi. Welcome to AWF!

Just checking, did you already see @isladogs' demo on controlling the application user interface?

PS. Sorry, the above response was from just reading the title of your thread. Upon re-reading your post, I think you could use the form's BeforeUpdate event to cancel the unfinished changes/edits and the form's UnLoad event to cancel the close event, if desired.
 

isladogs

MVP / VIP
Local time
Today, 05:26
Joined
Jan 14, 2017
Messages
18,209
As @theDBguy has already mentioned you can & should do all the validation checks using the Form_BeforeUpdate event.

However, some of your other questions are relevant to my article and example app Control Application Interface - Mendip Data Systems.
I'm answering on my tablet so won't go into great detail now but for example the app shows the following and much more
- borderless forms have no title bar so no close button etc but API code can be used to drag the form to a new position.
- they can also be resized.

BTW I tried looking at your file but it won't run properly in 64-bit Access which is what I have on my tablet.
 
Last edited:

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 12:26
Joined
May 7, 2009
Messages
19,228
you don't need such many codes and API calls.
your only purpose is to have a check if All Required fields are filled
when the X button is pressed?

use Transaction in your form.
see this demo.
note i removed some of your Module, since i have no time to convert them to x64.
 

Attachments

  • testCustomTitlebar.zip
    91.1 KB · Views: 315

lolgoodone

New member
Local time
Today, 06:26
Joined
Sep 15, 2020
Messages
4
Thank you for the quick responses, I'have a look at all of them.
If I may, I might post follow-up questions or whether I managed to implement your feedback ^^
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 00:26
Joined
Feb 19, 2002
Messages
43,213
making sure that a user just can't press "x" and close the form with a half finished entry?
As others have mentioned, the form's BeforeUpdate event is the place to trap invalid/incomplete data.

Think of the beforeUpdate event as the flapper at the bottom of a funnel. If the flapper is open, the record saves. If the flapper is closed, it doesn't. It is just that simple when you use the correct event. Give the user a meaningful error message and use the Cancel argument to tell Access to not save the record:

Cancel = True

The Close event runs AFTER the record has already been saved so it is too late to be useful for this purpose.
 

lolgoodone

New member
Local time
Today, 06:26
Joined
Sep 15, 2020
Messages
4
Hello again,

I found a working solution now.
For some reason

Code:
 If Me.Dirty Then
    Cancel = True
End If

is not working in the Form_UNLOAD event, but I have a seperate field, that checks whether a record is being edited or not. Based on that field I can check if the record is dirty or not. I'm sure there are many better ways to do this, but for now I'm happy that it works.

@arnelgp I'm struggling to understand the sample database you shared. The concept of transactions is clear and I understand the code in the class module to 90%, but I cannot manage to save the data from the form into the table. The buttons are hooked up to their respective declaration in t.form.Init.
E.g. I press the button NEW (hooked up to m_save_add_Click), enter data, then press the button SAVE (hooked up to m_save_quit_Click), but the record doesn't get saved to the table. What am I doing wrong?

Thanks you and best regards!
 
Last edited:

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 21:26
Joined
Oct 29, 2018
Messages
21,449
... is not working in the Form_Close event,
Probably because the Close event does not have a Cancel argument. Look at the code definition of the Open and BeforeUpdate events and compare them against the code definition of the Close event to see the difference.
 

lolgoodone

New member
Local time
Today, 06:26
Joined
Sep 15, 2020
Messages
4
Probably because the Close event does not have a Cancel argument. Look at the code definition of the Open and BeforeUpdate events and compare them against the code definition of the Close event to see the difference.

Yes, right, I didn't double check - I meant the Form_UNLOAD event :)
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 00:26
Joined
Feb 19, 2002
Messages
43,213
I found a working solution now.
For some reason

Code:Copy to clipboard
If Me.Dirty Then
Cancel = True
End If
Hate to burst your bubble but that isn't the solution. At least THREE experts, maybe more told you how to control whether or not a record gets saved.
USE THE form's BeforeUpdate event.
If you have questions regarding how to correctly use the form's BeforeUpdate event, we're happy to help.
 

Users who are viewing this thread

Top Bottom