multiple forms (1 Viewer)

DanielR

Registered User.
Local time
Today, 14:13
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?
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 17:13
Joined
Feb 19, 2002
Messages
43,233
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.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 05:13
Joined
May 7, 2009
Messages
19,229
You need an API to Set the pop up to Foreground
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 05:13
Joined
May 7, 2009
Messages
19,229
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
 

Frothingslosh

Premier Pale Stale Ale
Local time
Today, 17:13
Joined
Oct 17, 2012
Messages
3,276
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:

Pat Hartman

Super Moderator
Staff member
Local time
Today, 17:13
Joined
Feb 19, 2002
Messages
43,233
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

Top Bottom