Avatar billede magerlin Nybegynder
13. januar 2005 - 09:43 Der er 3 kommentarer og
1 løsning

Closing form by using macro, even if ctrl+F4 or close in fileMenu

Hi Guys, Danish will do just as fine.
The Form f-reg is used to enter data into the main table.
The problom is if the user closes the form,
choosing Close from the File menu, moves to a different record, applies or
removes a filter or a new ordering, presses Ctrl+F4, etc. My close macro isn't run, and this causes "half" records. So I need to make a solution that either run the macro or blanks all fields no mater how it is closed. I think VBA will do the trick but How? A msgbox that asks weather to save or cancel  would be lovely.

The Query behind the form is called q-reg, in the form I have both combo (eg status) and text fields (eg activatedate) that has to bee blanked if not saved, and if saved they need to bee controled if they have a value (they are mandatory, not suposed to be blank).
Avatar billede lorentsnv Nybegynder
13. januar 2005 - 10:10 #1
You can enter code in Form_Close() event to control what happens when the user tries toclose the form.
Avatar billede lorentsnv Nybegynder
13. januar 2005 - 10:12 #2
Sorry, it should be Form_Unload event, you could have code like this:

Private Sub Form_Unload(Cancel As Integer)
    nReturn = MsgBox("Do you want to close?", vbYesNo)
    If nReturn = vbNo Then
        Cancel = True
    End If
End Sub
Avatar billede magerlin Nybegynder
13. januar 2005 - 11:14 #3
Can one disable the standard DoCmd.Close, because it is my impressiion that this is the one that is executed when closeing the form, choosing Close from the File menu, moves to a different record, presses Ctrl+F4, etc.
Or if I could set the DoCmd.Close to equal my close macro?
Avatar billede lorentsnv Nybegynder
13. januar 2005 - 11:39 #4
If you use the Form_Unload event, and insert the code from my previous answer, you could insert code where I have 'Cancel = True' to have Access ececuting some code, before unloading the form. The Unload event should execute even if you use DoCmd.Close.
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Dyk ned i databasernes verden på et af vores praksisnære Access-kurser

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester