Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
Access
3rdpartyusrgrp
access
activexcontrol
adp.sqlserver
commandbarsui
conversion
dataaccess.pages
developers.toolkitode
devtoolkits
externaldata
forms
formscoding
gettingstarted
internet
interopoledde
macros
modulescoding
modulesdaovba
modulesdaovba.ado
multiuser
odbcclientsvr
queries
replication
reports
security
setupconfig
tablesdbdesign
  
 
date: Wed, 24 Sep 2008 06:28:01 -0700,    group: microsoft.public.access.modulesdaovba        back       


Form OnDelete event   
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
date: Wed, 24 Sep 2008 06:28:01 -0700   author:   Steven

RE: Form OnDelete event   
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
date: Wed, 24 Sep 2008 09:06:01 -0700   author:   Steven

Re: Form OnDelete event   
"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)
date: Wed, 24 Sep 2008 12:41:47 -0400   author:   Dirk Goldgar lid

Re: Form OnDelete event   
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)
> 
>
date: Wed, 24 Sep 2008 12:26:05 -0700   author:   Steven

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us