473,406 Members | 2,377 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

How to count records selected in subform datasheet?

I have a form with a subform datasheet - I need code behind the OnDelete
event of the subform:

Private Sub Form_Delete(Cancel As Integer)
'do something that depends on which record is deleted
End Sub

This works okay when only one record is selected and the delete key is
pressed (or right-click delete is selected - makes no difference). But if
multiple records are selected in the datasheet, the code runs for the first
record only. Is there a way to loop through each selected record (when the
delete key is pressed)? For example, let's say there are 12 records in the
datasheet, and 5 are selected, then the delete key is pressed - how do I run
code for each selected record? Is it possible to count how many are
selected?

Thanks!

just as a further clarification, each record that is selected for deletion
has a record ID associated with it -- that is what I am after...
Nov 12 '05 #1
3 9081
rkc

"deko" <dj****@hotmail.com> wrote in message
news:Cj****************@newssvr25.news.prodigy.com ...
I have a form with a subform datasheet - I need code behind the OnDelete
event of the subform:

Private Sub Form_Delete(Cancel As Integer)
'do something that depends on which record is deleted
End Sub

This works okay when only one record is selected and the delete key is
pressed (or right-click delete is selected - makes no difference). But if
multiple records are selected in the datasheet, the code runs for the first record only.


What exactly are you trying to do?

When I try this the Delete event is fired, in succession, for each selected
record.

The following debug prints the asked for information for each
selected record when the Delete key is pressed.

Private Sub Form_Delete(Cancel As Integer)

With Me
Debug.Print !EmployeeID;" "; !LastName; " "; !FirstName
End With

Cancel = True
End Sub


Nov 12 '05 #2
hmmm...

I'll take another look at my code and post back...

"rkc" <rk*@yabba.dabba.do.rochester.rr.nope> wrote in message
news:ur******************@twister.nyroc.rr.com...

"deko" <dj****@hotmail.com> wrote in message
news:Cj****************@newssvr25.news.prodigy.com ...
I have a form with a subform datasheet - I need code behind the OnDelete
event of the subform:

Private Sub Form_Delete(Cancel As Integer)
'do something that depends on which record is deleted
End Sub

This works okay when only one record is selected and the delete key is
pressed (or right-click delete is selected - makes no difference). But if multiple records are selected in the datasheet, the code runs for the first
record only.


What exactly are you trying to do?

When I try this the Delete event is fired, in succession, for each

selected record.

The following debug prints the asked for information for each
selected record when the Delete key is pressed.

Private Sub Form_Delete(Cancel As Integer)

With Me
Debug.Print !EmployeeID;" "; !LastName; " "; !FirstName
End With

Cancel = True
End Sub


Nov 12 '05 #3
My problem was that I was trying to do everything in Form_BeforeDelConfirm -
rather than Form_Delete

Now I only have this in Form_BeforeDelConfirm:

Private Sub Form_BeforeDelConfirm(Cancel As Integer, Response As Integer)
Response = acDataErrContinue
End Sub

and do all the heavy lifting in Form_Delete.

here's the code if anyone's interested...

Private Sub Form_Delete(Cancel As Integer)
On Error GoTo HandleErr
Dim strDa As String
Dim j As String
Dim strDoc As String
Dim strSql As String
Dim strNh As String
Dim strHs As String
Dim strCh As String
Dim strOe As String
Dim strMsg As Variant
Dim intResponse As Integer
Dim lngCt As Long
Dim rst As DAO.Recordset
Dim objFile As Object
strDoc = HyperlinkPart(Me!Document, 0)
intResponse = MsgBox("Are you sure you want to unlink the document:" &
vbCrLf & vbCrLf & strDoc & " ?", vbQuestion + vbOKCancel + vbDefaultButton1,
" Confirm Unlink")
If intResponse = vbCancel Then
Cancel = True
Exit Sub
End If
'get list of any other entities linked to document
strSql = "SELECT Entity_ID FROM tblDocuments WHERE
HyperlinkPart(Document, 0) = " & Chr(34) & strDoc & Chr(34) & " AND
Entity_ID <> " & Me!Entity_ID
Set rst = CurrentDb.OpenRecordset(strSql)
Do Until rst.EOF
lngEid = rst!Entity_ID
strNh = Nz(DLookup("FullName", "qryEntity", "Entity_ID = " & lngEid), 0)
strCh = Nz(DLookup("Company", "qryEntity", "Entity_ID = " & lngEid), 0)
If strNh = "0" Then
strHs = strCh
End If
If strCh = "0" Then
strHs = strNh
End If
If strNh <> "0" And strCh <> "0" Then
strHs = strNh & ", " & strCh
End If
strOe = "Entity ID " & lngEid & vbTab & strHs & vbCrLf & strOe
rst.MoveNext
Loop
lngCt = rst.RecordCount
'alert to other entities linked to document
If lngCt = 1 Then
strMsg = "The following entity is also linked to " & strDoc & ": "
Else
strMsg = "The following entities are also linked to " & strDoc & ":
"
End If
If lngCt >= 1 Then intResponse = MsgBox(strMsg & vbCrLf & vbCrLf &
strOe, vbInformation, " Other Entities Linked To Document")
If DLookup("DocOpt", "tblOutput") <> 3 Then 'deletion only applicable
when using linked document folder
intResponse = MsgBox("Do you want to delete " & strDoc & " after it
is unlinked from this entity?", vbYesNo + vbExclamation + vbDefaultButton1,
" Confirm Delete")
If intResponse = vbYes Then
j = (InStr(1, Me!Document, "#", 1)) + 7
strDa = Right(Me!Document, Len(Me!Document) - j)
Set objFile = CreateObject("Scripting.FileSystemObject")
objFile.DeleteFile strDa
End If
End If
Set objFile = Nothing
DoCmd.SetWarnings False
DoCmd.OpenQuery "qryModDocs"
DoCmd.SetWarnings True
Exit_Here:
Exit Sub
HandleErr:
Select Case Err.Number
Case 52 'Bad file name or number
Resume Next
Case 53 'File not found
Resume Next
Case Else
modHandler.LogErr (Me.Form.Name)
Resume Exit_Here
End Select
End Sub

"rkc" <rk*@yabba.dabba.do.rochester.rr.nope> wrote in message
news:ur******************@twister.nyroc.rr.com...

"deko" <dj****@hotmail.com> wrote in message
news:Cj****************@newssvr25.news.prodigy.com ...
I have a form with a subform datasheet - I need code behind the OnDelete
event of the subform:

Private Sub Form_Delete(Cancel As Integer)
'do something that depends on which record is deleted
End Sub

This works okay when only one record is selected and the delete key is
pressed (or right-click delete is selected - makes no difference). But if multiple records are selected in the datasheet, the code runs for the first
record only.


What exactly are you trying to do?

When I try this the Delete event is fired, in succession, for each

selected record.

The following debug prints the asked for information for each
selected record when the Delete key is pressed.

Private Sub Form_Delete(Cancel As Integer)

With Me
Debug.Print !EmployeeID;" "; !LastName; " "; !FirstName
End With

Cancel = True
End Sub


Nov 12 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Terri | last post by:
I have a form with a multi-select combo. I dynamically build a SELECT statement, open a report, and set the recordsource to my dynamic SELECT statement. I count the records returned in the report...
6
by: Robin S. | last post by:
**Eric and Salad - thank you both for the polite kick in the butt. I hope I've done a better job of explaining myself below. I am trying to produce a form to add products to a table (new...
12
by: MLH | last post by:
I have created two forms: frmBrowseNegsMainform and frmBrowseNegsSubform. I put a subform control on the first of these. The SourceObject property for the subform control is, of course,...
2
by: origin197511 | last post by:
Hello all... I'm having an issue with MSAccess 2000. I have a Form that holds records of my cartridge loads for a rifle and a subform that lists all groups that have been fired with that load. ...
3
by: Roy | last post by:
Hello, Sorry for a lengthy post. I develop a access 2000 application.As a part of the daily download,I import data from a excel sheet into a access table. The data is as follows: Task...
1
by: Thomas Zimmermann | last post by:
I have a form with a subform in datasheet view. Now, I want to trigger a procedure (P1) each time the user selects an entire column (by clicking in the heading) in the subform. The procedure (P1) I...
5
by: steph | last post by:
Hi, I'm a bit of an access-dummy, and i suppose this problem of mine has a rather simple solution, but nevertheless i'm not sure i see it at the moment. I've got an access-form in...
5
by: Kaur | last post by:
Hi, I have been successful copying a vba code from one of your posts on how to copy and paste a record by declaring the desired fields that needs to be copied in form's declaration and creating two...
10
by: Michael R | last post by:
Hello to all. In what way can I update a certain selected records' values on a datasheet subform using a command button which is located on the main form? Thanks and cheers.
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.