Results 1 to 3 of 3
  1. #1
    Join Date
    May 2010
    Location
    Islamabad
    Posts
    13

    Prompt on close and don't save the null record


    Slaam to all.
    hey everyone.

    i have form with some txt fields and close button.

    i want that when user click on close button then access generate a message with yes and no button.

    which is such as" Are you sure to close Application" vb yes or no
    when use press yes then access check only two fields for null and if both or one null then record not saved in table all things work good but only saving issued not solved. for this purpose i used cancel = true if msgbox = vbyes but it save the record even both fields are empty. what problem with code I cann't understand.

    the code behind close button is :
    -------------------------------------------------------------------------
    Code:
    Private Sub cmdClose_Click()
    Dim strmsg As String
    On Error GoTo Err_cmdClose_Click
    
    strmsg = "Are you sure to close Application"
    
    If MsgBox(strmsg, vbQuestion + vbYesNo, "Close Application") = vbYes Then
        If IsNull(Me.WithDrawAmount) Or IsNull(Me.Description) Then
            MsgBox ("Record will be not saved")
            End If
    Cancel = True
    DoCmd.Close acForm, "WithDrawSpecial"
    Else
        If IsNull(Me.WithDrawAmount) Or IsNull(Me.Description) Then
        Me.WithDrawAmount.BorderColor = vbRed
        Me.Description.BorderColor = vbRed
        End If
    End If
    
    Exit_cmdClose_Click:
        Exit Sub
    
    Err_cmdClose_Click:
        MsgBox Err.Description
        Resume Exit_cmdClose_Click
        
    End Sub
    ----------------------------------------------------------------
    any ideas, suggestion, will be appreciated.

  2. #2
    Join Date
    May 2010
    Location
    Islamabad
    Posts
    13
    this code works good. i have a main form "Account" where i click on cmdWithDrawAmount button to open withdrawspecial form for amount entry in concern account record. withdrawspecial form open using openArgs properity for opening in same record as in "Account".

    Form withdrawspecial also have some other fields like accountid which filledup automically by Account OpenArgs Properity. TranscationID (autonumber) field, WithDrawAmount field and Description fields.

    i want that when user open withdrawspecial form for amount entry but he click on close button to close the form without filling WithDrawAmount field and Description field then access generate message box with yes or no button. if user click on yes then form close without saving the records and if he/she click on no then both fields border get red.

    is it impossible to prevent saving the record if only two above said fields empty.

  3. #3
    slave138's Avatar
    slave138 is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Oct 2010
    Location
    WI
    Posts
    233
    This change might work in your function:
    Code:
    ...
    If MsgBox(strmsg, vbQuestion + vbYesNo, "Close Application") = vbYes Then
        If IsNull(Me.WithDrawAmount) Or IsNull(Me.Description) Then
            MsgBox ("Record will be not saved")
            DoCmd.RunCommand acCmdUndo
        End If
        DoCmd.Close acForm, "WithDrawSpecial"
    Else
        If IsNull(Me.WithDrawAmount) Or IsNull(Me.Description) Then
            Me.WithDrawAmount.BorderColor = vbRed
            Me.Description.BorderColor = vbRed
            DoCmd.CancelEvent
        End If
    End If
    ...
    Move the function to the BeforeUpdate event instead of the OnClose.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. form won't save and close
    By Philislost in forum Access
    Replies: 6
    Last Post: 10-08-2010, 01:47 PM
  2. Duplicate Record Cannot Save
    By magicscreen in forum Programming
    Replies: 2
    Last Post: 09-15-2010, 08:15 AM
  3. Replies: 5
    Last Post: 02-10-2010, 12:27 AM
  4. Replies: 2
    Last Post: 01-29-2010, 11:33 AM
  5. Null vs New Record
    By jversiz in forum Access
    Replies: 2
    Last Post: 02-20-2008, 12:02 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums