Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Close form without updating the tables 1

Status
Not open for further replies.

Superguppie

Technical User
Jan 19, 2005
107
NL
hi all,

when a user opens a form and fills in information in a Subform... and then click on de normal form on Close without save, the record must be cleaned so it wont go into database (table) this must be done trough VBA code, because there is more code that has to be done in same button:S hope someone can help me:D

Greetz

Patrick Strijdonck
 
Superguppie . . .

For a subform, the current edited record is saved when you:
[ol][li]Move the focus to another subform record.[/li]
[li]Move the focus to any control on the mainform.[/li]
[li]Click the form or access application close button [blue]X[/blue].[/li][/ol]
The close buttons can be disabled so you can use your own, however as stated above, the [blue]focus has to move from the subform causing a save![/blue]

One way around this is to keep focus on the subform by having your own close button there and [purple]executing Me.Undo within the code.[/purple] Although this would work its ambiguous, as [purple]there's no way to know if the user intended to save![/purple]

What I suggest is a prompt (msgbox) that allows the user to [blue]save, go back to make changes, or remove the record.[/blue] The only caveat is the prompt occurs for each edited record. As an Example, copy/paste the following to the subforms [blue]Before Update[/blue] event:
Code:
[blue]   Dim Msg As String, Style As Integer, Title As String
   Dim DL As String, AnsMsg As Integer
   
   DL = vbNewLine & vbNewLine
   Msg = "Save This Record?" & DL & _
         "Click 'Yes' to Save." & DL & _
         "Click 'No' to go back and make changes." & DL & _
         "Click 'Cancel' to abort saving and close."
   Style = vbQuestion + vbYesNoCancel
   Title = "User Input required! . . ."
   AnsMsg = MsgBox(Msg, Style, Title)
   
   If AnsMsg = vbNo Then
      Cancel = True
   ElseIf AnsMsg = vbCancel Then
      Me.Undo
      DoCmd.Close acForm, "[purple][B][I]MainFormName[/I][/B][/purple]"
   End If[/blue]
[blue]Your Thoughts? . . .[/blue]

Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997
Also faq181-2886
 
I tried your code and changed it to my own taste, and it works, and it gave me another option for my database, so the code worked for me:D

The problem is solved now thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top