I have the following to not allow a user to delete more than one record at a time in the form. The issue is that if more than one record (for example if 3 records were selected) then the MsgBox will show 3 times and etc. How would you make it so the MsgBox will appear only one time? Private Sub Form_Delete(Cancel As Integer) If Me.SelHeight > 1 Then Cancel = True MsgBox "Cannot delete more than one record at a time." Exit Sub End If '....continue End Sub Thank you, Steven
I did a workaround by setting up a Public variable in the form's code and then counting how many passes had been made through the On Delete and used logic to test the count to the SelHeight to make it so the MsgBox would only show one time. "Steven" wrote: > I have the following to not allow a user to delete more than one record at a > time in the form. The issue is that if more than one record (for example if > 3 records were selected) then the MsgBox will show 3 times and etc. > > How would you make it so the MsgBox will appear only one time? > > Private Sub Form_Delete(Cancel As Integer) > If Me.SelHeight > 1 Then > Cancel = True > MsgBox "Cannot delete more than one record at a time." > Exit Sub > End If > '....continue > End Sub > > Thank you, > > Steven
"Steven" wrote in message news:AFDBC14D-A5A3-4DBB-9630-1AE536632897@microsoft.com... >I have the following to not allow a user to delete more than one record at >a > time in the form. The issue is that if more than one record (for example > if > 3 records were selected) then the MsgBox will show 3 times and etc. > > How would you make it so the MsgBox will appear only one time? > > Private Sub Form_Delete(Cancel As Integer) > If Me.SelHeight > 1 Then > Cancel = True > MsgBox "Cannot delete more than one record at a time." > Exit Sub > End If > '....continue > End Sub This seems to work: '----- start of code ----- Private Sub Form_Delete(Cancel As Integer) Static NDeletes As Integer NDeletes = NDeletes + 1 If Me.SelHeight > 1 Then Cancel = True If NDeletes = Me.SelHeight Then MsgBox "Cannot delete more than one record at a time." NDeletes = 0 End If Else NDeletes = 0 End If End Sub '----- end of code ----- -- Dirk Goldgar, MS Access MVP www.datagnostics.com (please reply to the newsgroup)
Dirk, I was able to make it work basically with something like you did but I did not use Static ...... That is interesting. Thank you. Steven "Dirk Goldgar" wrote: > "Steven" wrote in message > news:AFDBC14D-A5A3-4DBB-9630-1AE536632897@microsoft.com... > >I have the following to not allow a user to delete more than one record at > >a > > time in the form. The issue is that if more than one record (for example > > if > > 3 records were selected) then the MsgBox will show 3 times and etc. > > > > How would you make it so the MsgBox will appear only one time? > > > > Private Sub Form_Delete(Cancel As Integer) > > If Me.SelHeight > 1 Then > > Cancel = True > > MsgBox "Cannot delete more than one record at a time." > > Exit Sub > > End If > > '....continue > > End Sub > > This seems to work: > > '----- start of code ----- > Private Sub Form_Delete(Cancel As Integer) > > Static NDeletes As Integer > > NDeletes = NDeletes + 1 > > If Me.SelHeight > 1 Then > Cancel = True > If NDeletes = Me.SelHeight Then > MsgBox "Cannot delete more than one record at a time." > NDeletes = 0 > End If > Else > NDeletes = 0 > End If > > End Sub > > '----- end of code ----- > > > > -- > Dirk Goldgar, MS Access MVP > www.datagnostics.com > > (please reply to the newsgroup) > >