Results 1 to 3 of 3

Thread: Form close

  1. #1
    Join Date
    Jan 2007
    Posts
    47

    Unanswered: Form close

    Hi,

    I am working on a database which was created by soemone. It has a multiple forms and one main table which has no primary key. The main form contains "Add record" and "cancel" buttons. When I click cancel button nothing should get saved in the database table. This works fine. The issue I am having is if some enters the database (main form) and just clloses it without clicking it "cancel" button empty record with blank fields are getting saved into the table and this is effecting reporting production summary.

    Is there a way I can close the form without getting saved anything in to the main table. I tried to set multiple field Primary key on my table but it doesn't allow me to do it as I already have records with null values and duplicates in the table. Please advise me on this.

    Thanks,

  2. #2
    Join Date
    May 2003
    Location
    New York, NY
    Posts
    225
    Quote Originally Posted by ujjwala
    Hi,

    I am working on a database which was created by soemone. It has a multiple forms and one main table which has no primary key. The main form contains "Add record" and "cancel" buttons. When I click cancel button nothing should get saved in the database table. This works fine. The issue I am having is if some enters the database (main form) and just clloses it without clicking it "cancel" button empty record with blank fields are getting saved into the table and this is effecting reporting production summary.

    Is there a way I can close the form without getting saved anything in to the main table. I tried to set multiple field Primary key on my table but it doesn't allow me to do it as I already have records with null values and duplicates in the table. Please advise me on this.

    Thanks,
    You may want to think about using a ADO to manipulate your date.

  3. #3
    Join Date
    Apr 2004
    Location
    Derbyshire, UK
    Posts
    789
    Provided Answers: 1
    Hi

    You realy do need to sort out the data and set some PKs if at all possible.

    I normaly have this code in the cmdClose_Click, but if you do not have a close button (I never have the contol box/Close button visible) then it could be adapted for the form close/unload event ?

    Code:
    Private Sub cmdClose_Click()
    On Error GoTo Err_cmdClose_Click
        Dim Ans As Integer
        If Me.Dirty Then
            Ans = MsgBox("Do you want to save this new job and close then form ?", vbYesNoCancel, msgTitle)
            If Ans = vbYes Then
                If DataOK Then
                    DoCmd.RunCommand acCmdSaveRecord
                Else
                    Exit Sub
                End If
            ElseIf Ans = vbNo Then
                DoCmd.RunCommand acCmdUndo
            Else
                Exit Sub
            End If
        End If
        DoCmd.Close
    
    Exit_cmdClose_Click:
        Exit Sub
    
    Err_cmdClose_Click:
        MsgBox Err.Description, vbCritical, msgTitle
        Resume Exit_cmdClose_Click
        
    End Sub

    (note DataOK is a function that validates the data)

    Just a suggestion.


    MTB

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •