oxidus5886
New member
- Local time
- Today, 14:51
- Joined
- May 27, 2009
- Messages
- 6
Hi,
This is my first post and I am really really new to coding in VB so youll have to bear with me.
I am trying to create a form in access which has a close button which closes the form. I have tried to design the form as data entry only, so all record navigation has been removed from the form and it is set to add new record on open. This is all fine.
I need to make it so that when the form is closed, the form cancels and deletes any record currently being edited in the current run through. The whole idea is that there will be a sequence of forms which open for the user to input data relating to the same item across multiple forms. Also the user must not be able to change anything already submitted.
I also need a dialog box to appear to warn the user about loss of progress with the data entry when the form is attempting to close.
Here's what I have so far on close:
Private Sub Form_Close()
If Me.Dirty Then GoTo DIALOG:
GoTo CLOSEFORMNOSAVE:
DIALOG:
MsgBox "Exiting the Add Car system now will delete any progress made. Are you sure you want to exit?", vbYesNo
If vbYes Then
GoTo CLOSEFORM:
ElseIf vbNo Then
GoTo CANCELCLOSE:
End If
CLOSEFORM:
DoCmd.RunCommand acCmdDeleteRecord
DoCmd.Close acForm, "Add Cars", acSaveNo
Exit Sub
CANCELCLOSE:
Exit Sub
CLOSEFORMNOSAVE:
End Sub
I know that this is probably full of bugs and errors. Essentially the form just closes and saves any data entered so far. Please could someone help me with this, I have been tearing my hair out. I am very limited with what I know, only what I've picked up from forums and help files. I would like to keep the commands and structure similar if I can, otherwise I will just get lost.
.
Any help would be greatly appreciated.
Thanks,
Adam
This is my first post and I am really really new to coding in VB so youll have to bear with me.
I am trying to create a form in access which has a close button which closes the form. I have tried to design the form as data entry only, so all record navigation has been removed from the form and it is set to add new record on open. This is all fine.
I need to make it so that when the form is closed, the form cancels and deletes any record currently being edited in the current run through. The whole idea is that there will be a sequence of forms which open for the user to input data relating to the same item across multiple forms. Also the user must not be able to change anything already submitted.
I also need a dialog box to appear to warn the user about loss of progress with the data entry when the form is attempting to close.
Here's what I have so far on close:
Private Sub Form_Close()
If Me.Dirty Then GoTo DIALOG:
GoTo CLOSEFORMNOSAVE:
DIALOG:
MsgBox "Exiting the Add Car system now will delete any progress made. Are you sure you want to exit?", vbYesNo
If vbYes Then
GoTo CLOSEFORM:
ElseIf vbNo Then
GoTo CANCELCLOSE:
End If
CLOSEFORM:
DoCmd.RunCommand acCmdDeleteRecord
DoCmd.Close acForm, "Add Cars", acSaveNo
Exit Sub
CANCELCLOSE:
Exit Sub
CLOSEFORMNOSAVE:
End Sub
I know that this is probably full of bugs and errors. Essentially the form just closes and saves any data entered so far. Please could someone help me with this, I have been tearing my hair out. I am very limited with what I know, only what I've picked up from forums and help files. I would like to keep the commands and structure similar if I can, otherwise I will just get lost.

Any help would be greatly appreciated.
Thanks,
Adam