not save data until click 'ok'

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • stabesh
    New Member
    • May 2010
    • 4

    not save data until click 'ok'

    hi
    I have a problem
    I want not save data until click 'ok'
    and Do not save anything when click 'cancel'
    in form and subform

    i'm find two file (in attachments)
    but incorrect

    please help me
    Attached Files
  • beacon
    Contributor
    • Aug 2007
    • 579

    #2
    I always create an unbound form and use the SQL INSERT INTO query to put the data from the fields in my form into the table. I add the INSERT query to the Click event of a command button, usually called 'Save' or 'Submit'.

    Here's an example of a Click event with an INSERT query:
    Code:
    Private Sub cmdSave_Click()
    
         Dim strSQL As String
    
         'Assuming that TableFields are fields in your table
         'Assuming that FormFields are fields on your form
         'Assumes that FormField1 is numeric, FormField2 is a string, and FormField3 is a date
         strSQL = "INSERT INTO YourTable([TableField1], [TableField2], [TableField3]) VALUES (" & Me.FormField1 & ", '" & Me.FormField2 & ", #" & Me.FormField3 & "#);"
    
         Msgbox "Save Complete"
    
    End Sub
    To cancel, just create a command button similar to the above, except instead of using the SQL query, just use the following:
    Code:
    Private Sub Cancel_Click()
    
         Dim userSelection
        
         userSelection = MsgBox("Are you sure you want to close the form without saving?", vbExclamation + vbYesNo, "Cancel")
        
        If userSelection = vbYes Then
            DoCmd.Close acForm, Me.Name
            MsgBox "You will now be returned to the Main Menu", vbOKOnly + vbInformation, "Return to Main Menu"
            DoCmd.OpenForm "Switchboard"
        ElseIf userSelection = vbNo Then
            Exit Sub
        Else
            MsgBox "An error has occurred. You will be returned to the form.", vbCritical + vbOKOnly, "Error"
            Exit Sub
        End If
    End Sub
    Hope this helps,
    beacon

    Comment

    • stabesh
      New Member
      • May 2010
      • 4

      #3
      thank youuuuuuuu

      Comment

      • stabesh
        New Member
        • May 2010
        • 4

        #4
        hi
        I'm find it

        Is exist any better way ?

        thanks
        Attached Files

        Comment

        Working...