Determining how many rows are selected - subform

G

Guest

I want to send specific type of warning, if a certain record is WITHIN a
multiple selection of rows in a subform in datasheet view.

For example, if a user just selects 1 row, I have no problem using the ID
field of that row for further instructions...

However, if multiple rows are selected, it is more difficult to determine if
a certain "marked" row has also been selected.

More specifically, if the user selects 10 rows, altogether, and 2 rows (say
5 and 8) shouldn't be allowed to be deleted, how could I warn the user of
rows 5 and 8?

Thanks in advance!
 
D

Dirk Goldgar

jonefer said:
I want to send specific type of warning, if a certain record is
WITHIN a multiple selection of rows in a subform in datasheet view.

For example, if a user just selects 1 row, I have no problem using
the ID field of that row for further instructions...

However, if multiple rows are selected, it is more difficult to
determine if a certain "marked" row has also been selected.

More specifically, if the user selects 10 rows, altogether, and 2
rows (say 5 and 8) shouldn't be allowed to be deleted, how could I
warn the user of rows 5 and 8?

Thanks in advance!

This may not answer your question directly, but did you know that the
Delete event fires for every record to be deleted, even if you have
selected multiple records? And that you can cancel that event to keep
that record from being deleted? So if you want, you can prevent rows 5
and 8 from being deleted, and alert the user to that effect, without
preventing the deletion of the remaining rows that were selected.

Would this approach do what you want?
 
G

Guest

Hi.
However, if multiple rows are selected, it is more difficult to determine if
a certain "marked" row has also been selected.

More specifically, if the user selects 10 rows, altogether, and 2 rows (say
5 and 8) shouldn't be allowed to be deleted, how could I warn the user of
rows 5 and 8?

I have no idea what criteria you are using to determine why a selected row
shouldn't be deleted, so I can't offer much guidance other than to suggest
that you read the MS KB article, "How to enumerate selected form records in
Access 2002," on the following Web page:

http://support.microsoft.com/default.aspx?id=294202

If you are using Access 2000, then please see the following Web page:

http://support.microsoft.com/kb/208502/EN-US/

If you are using Access 97, then please see the following Web page:

http://support.microsoft.com/kb/148393/

HTH.
Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips.

(Please remove ZERO_SPAM from my reply E-mail address so that a message will
be forwarded to me.)
- - -
If my answer has helped you, please sign in and answer yes to the question
"Did this post answer your question?" at the bottom of the message, which
adds your question and the answers to the database of answers. Remember that
questions answered the quickest are often from those who have a history of
rewarding the contributors who have taken the time to answer questions
correctly.
 
G

Guest

I thought so, and wrote something to intercept those particular records, but
it went ahead and deleted them anyway.

This is what I did:
'==============================
Sub Form_BeforeDelConifrm(Cancel as integer, Response as Integer)
if DCount("*" , "qryCheckForFieldsInReport") > 0 then
MsgBox "Record " & me.FieldID & " is being used in a report"
Cancel = True
End If

End Sub
'===============================

This is how I would like to handle it, it seems pretty simple
So, if I just need to adjust this, would you show me? I would prefer it...
Thanks again.
 
G

Guest

Will this work with the form in Datasheet View?

I tried putting the click event of the 'Display Selected Company Names'
in my BeforeDelete Confirm event... But it seems as though I need those
mouse events that are attached to the button (which I won't be using)...
maybe I just don't understand what this is supposed to be acomplishing.
 
D

Dirk Goldgar

jonefer said:
I thought so, and wrote something to intercept those particular
records, but it went ahead and deleted them anyway.

This is what I did:
'==============================
Sub Form_BeforeDelConifrm(Cancel as integer, Response as Integer)
if DCount("*" , "qryCheckForFieldsInReport") > 0 then
MsgBox "Record " & me.FieldID & " is being used in a report"
Cancel = True
End If

End Sub
'===============================

This is how I would like to handle it, it seems pretty simple
So, if I just need to adjust this, would you show me? I would prefer
it... Thanks again.

I didn't say to use the BeforeDelConfirm event, I said to use the Delete
event. BeforeDelConfirm fires only once, after all the records have
been provisionally deleted (but they can be restored if you tell the
prompt you don't want to do it after all).

I don't know what your query, "qryCheckForFieldsInReport", does, so I
don't know if that will work in this context. If it will, then you
would need to write this event procedure instead of what you had:

'----- start of code -----
Sub Form_Delete(Cancel As Integer)

If DCount("*" , "qryCheckForFieldsInReport") > 0 Then
MsgBox "Record " & Me.FieldID & " is being used in a report"
Cancel = True
End If

End Sub

'----- end of code -----

I can't promise that will work, though, because of my uncertainty about
what's going on in that query.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top