Error msg on form with closing

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Sandhya1988
    New Member
    • Oct 2014
    • 30

    Error msg on form with closing

    Hello friends, Can any one help on my issue

    I got an error msg on form with closing. I have a main form (SalesReturnOrD amaged) and subform (SalesReturnOrD amagedSubform).

    So if empty form close then i need to without save the record. So in this case i have used a VBA code on Close Command button as per shown in Code Tag. But that is not working and shown an error msg as per screenshot. Can you please replay how to give a VBA code for empty form close without save the record?

    I have attached the dB and screen shot with explanation.

    Code:
    Private Sub Close_Click()
    On Error GoTo Err_Close_Click
    
    If Forms![SalesReturnOrDamaged]![SalesReturnOrDamagedSubform].Form![ItemCode].Value = "" Then
       Forms![SalesReturnOrDamaged]![SalesReturnOrDamagedSubform].Form![Product].Value = ""
       Forms![SalesReturnOrDamaged]![SalesReturnOrDamagedSubform].Form![MRP].Value = 0 Or ""
       Forms![SalesReturnOrDamaged]![SalesReturnOrDamagedSubform].Form![Qty].Value = 0 Or ""
    Beep
    If MsgBox("Do you want to delete this Return Record? Because Subform Product details are not updated properly.", vbYesNo, "Delete Confirmation") = vbYes Then
       DoCmd.RunCommand acCmdDeleteRecord
    Else
       GoTo Exit_Close_Click
    End If
    End If
    
    DoCmd.Close
    Exit_Close_Click:
    Exit Sub
    Err_Close_Click:
    MsgBox Err.Description
    Resume Exit_Close_Click
    
    End Sub
    Attached Files
  • twinnyfo
    Recognized Expert Moderator Specialist
    • Nov 2011
    • 3662

    #2
    One way to do this is to have unbound controls, and if the user wants to save the record, then it appends the data to the table. Remember, when you have bound controls on a Form, any time any text box is updated, the data is "saved".

    You could also try adding
    Code:
    Me.Undo
    after the Beep, which should get rid of any changes to that record.

    Comment

    • Sandhya1988
      New Member
      • Oct 2014
      • 30

      #3
      Actually i don't have better knowledge on VBA and creating unbound controls i think it’s mostly depending on coding. So i can design the forms directly from tables. So there is any way to work with above VBA code type?? I think just edit the above on the screen code can you please help how to change the above code?

      Comment

      Working...