473,783 Members | 2,516 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(Can cel 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 9111
rkc

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

Private Sub Form_Delete(Can cel 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(Can cel 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.dabb a.do.rochester. rr.nope> wrote in message
news:ur******** **********@twis ter.nyroc.rr.co m...

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

Private Sub Form_Delete(Can cel 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(Can cel 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_BeforeDelC onfirm -
rather than Form_Delete

Now I only have this in Form_BeforeDelC onfirm:

Private Sub Form_BeforeDelC onfirm(Cancel As Integer, Response As Integer)
Response = acDataErrContin ue
End Sub

and do all the heavy lifting in Form_Delete.

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

Private Sub Form_Delete(Can cel 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(M e!Document, 0)
intResponse = MsgBox("Are you sure you want to unlink the document:" &
vbCrLf & vbCrLf & strDoc & " ?", vbQuestion + vbOKCancel + vbDefaultButton 1,
" 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(D ocument, 0) = " & Chr(34) & strDoc & Chr(34) & " AND
Entity_ID <> " & Me!Entity_ID
Set rst = CurrentDb.OpenR ecordset(strSql )
Do Until rst.EOF
lngEid = rst!Entity_ID
strNh = Nz(DLookup("Ful lName", "qryEntity" , "Entity_ID = " & lngEid), 0)
strCh = Nz(DLookup("Com pany", "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 + vbDefaultButton 1,
" Confirm Delete")
If intResponse = vbYes Then
j = (InStr(1, Me!Document, "#", 1)) + 7
strDa = Right(Me!Docume nt, Len(Me!Document ) - j)
Set objFile = CreateObject("S cripting.FileSy stemObject")
objFile.DeleteF ile strDa
End If
End If
Set objFile = Nothing
DoCmd.SetWarnin gs False
DoCmd.OpenQuery "qryModDocs "
DoCmd.SetWarnin gs 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.LogE rr (Me.Form.Name)
Resume Exit_Here
End Select
End Sub

"rkc" <rk*@yabba.dabb a.do.rochester. rr.nope> wrote in message
news:ur******** **********@twis ter.nyroc.rr.co m...

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

Private Sub Form_Delete(Can cel 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(Can cel 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
8304
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 by setting a text box to =Count(*). This works fine. Now I want to count the unique records in my report. I can dynamically create a SELECT statement that counts unique records. My statement looks like this: SELECT DISTINCT...
6
2506
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 products). Tables: tblCategoryDetails CategoryID SpecID
12
19015
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, frmBrowseNegsSubform. I would like to perform an ascending or descending sort on any of the 7 columns shown in datasheet view in the subform control. I've been unsuccessful. Is there something tricky about sorting in subform controls?
2
4804
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. They are linked by the load_id field and when I just browse through the loads everything shows up correctly. Each recorded group is displayed on a line of the datasheet subform. However, when I filter the form for say my "Selected" flag...
3
1678
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 Comments 11801 08/02/2004 07:15:43 CET: Submitted 08/02/2004 06:35:39 CET: Please provide Post Mortem 11804 08/18/2004 09:33:46 CET: Sent mail to Carey Walker chasing
1
7008
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 want to trigger needs to be called with the selected column as a parameter. As far as I am aware, there is no event procedure for clicking in the heading of a datasheet. So insted I need to start by having an other procedure P0, which is...
5
6585
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 datasheet-view and i want to iterate over it's records and set some values according to our business logic. This action should be triggered by the user via a button. I suppose i need to access the record-set the form is based on doing something like:
5
13995
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 button "copy" and "paste". Works like magic. My problem is how can I copy multiple records and paste them at the same time. My data entry form has main form that has a Questionlist box of Questions. The second list box on the same form displays...
10
13401
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
9643
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9480
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10315
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10083
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8968
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7494
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6737
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2877
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.