multiple forms

DanielR

Registered User.
Local time
Today, 13:20
Joined
Mar 16, 2018
Messages
72
My forms have popup -> yes and modal -> yes.
When I close my current form I get the save window pop up however it does it on the parent window and the current window is now behind the parent window.
How can I ensure that the Parent window doesn't appear until the current window is closed?
 
You shouldn't be getting save prompts from forms. Do you have code that is modifying them?

Whatever messages you do get should be based on the order in which the forms are closed so the popup should be closed first.
 
You need an API to Set the pop up to Foreground
 
add copy and paste in a module.
on your pop up form Open Event:

Call SetForegroundWindow(Me.hwnd)

Code:
#if VBA7 then
	#If Win64 Then
		Declare PtrSafe Function SetForegroundWindow Lib "user32" (ByVal hWnd As LongPtr) As Long
	#else
		Declare PtrSafe Function SetForegroundWindow Lib "user32" (ByVal hWnd As Long) As Long
	#end if
#Else
	Declare Function SetForegroundWindow Lib "user32" (ByVal hWnd As Long) As Long
#End If
 
There's absolutely no need to use an API call for this.

When I'm using that kind of setup, I set the parent form to Hidden in the child form's Open event, and then set it back to visible in the child form's Close event (which technically runs before the form closes, but you won't normally be able to tell that).

And Pat's right - you shouldn't be getting a save popup when you close a form. Are you possibly modifying the record when the form opens? That would cause Access to ask if you want to save the record.

If it's asking you to save changes to the form itself, you can get around that by disabling the X-out button at the top-right of the form, and providing a close button instead. Have the close button use this code:

Code:
DoCmd.Close acForm, Me.Name, acSaveNo
Or shorten it to DoCmd.Close , , acSaveNo and you'll be fine like 99% of the time.
 
Last edited:
Modifying the record doesn't cause the save prompt. Access automatically saves every dirty record without prompting. Modifying the form design does that.
 

Users who are viewing this thread

Back
Top Bottom