Hi everybody,
This is probably going to sound unorthodox, but I have to log records that are deleted...I know, go figure.
Anyway, I have a form with a (continuous) subform, and on the subform I have a command button, called cmdDelete, that launches a dialog form, called frmDeleteCurren tRecord, where the user has to enter their name and a reason.
I have managed, through a ton of trial and tribulation, found a way to delete the current record on the subform from the query, qryEpisodeDetai l, using SQL. I had to pass parameters to the dialog form in order to create the delete query.
The problem I'm having, is that after the delete query runs and I'm returned to the subform, it says "#Deleted" in each of the controls on the subform. I have tried to refresh/requery in what feels like 100 different ways, but I keep getting error messages about how I need to save the current record.
Here's the code for the cmdDelete: -
Private Sub cmdDelete_Click()
-
-
Dim strConfirmDelete As String, strConfirmDeleteTitle As String
-
Dim strCancelDelete As String, strCancelDeleteTitle As String
-
Dim strNullDelete As String, strNullDeleteTitle As String
-
Dim varParameter
-
Dim varWhere As String
-
-
'Parameters to be passed 0-8
-
Dim strEpisodeDetailID, strPatientDetailIDFK, strFormIDFK, strDeficiencyIDFK
-
Dim strProgressNoteIDFK, strDeficiencyDate, strQuantity, strEmployeeIDFK
-
Dim strCorrectedDate
-
-
strConfirmDelete = "Are you sure you want to delete this record?" + Chr(13) + Chr(13) + "You will be required to log the deletion."
-
strConfirmDeleteTitle = "Confirm Delete"
-
strCancelDelete = "The delete operation has been cancelled."
-
strCancelDeleteTitle = "Delete Cancelled"
-
strNullDelete = "The record you are trying to delete does not exist."
-
strNullDeleteTitle = "Delete Failed: No Record"
-
-
varWhere = "[EpisodeDetailID] = " & Me.EpisodeDetailID
-
-
strEpisodeDetailID = Me.EpisodeDetailID
-
strPatientDetailIDFK = Me.PatientDetailIDFK
-
strFormIDFK = Me.FormIDFK
-
strDeficiencyIDFK = Me.DeficiencyIDFK
-
strProgressNoteIDFK = Me.ProgressNoteIDFK
-
strDeficiencyDate = Me.DeficiencyDate
-
strQuantity = Me.Quantity
-
strEmployeeIDFK = Me.EmployeeIDFK
-
strCorrectedDate = Me.CorrectedDate
-
-
varParameter = strEpisodeDetailID & ";" & strPatientDetailIDFK & ";" & strFormIDFK
-
varParameter = varParameter & ";" & strDeficiencyIDFK & ";" & strProgressNoteIDFK
-
varParameter = varParameter & ";" & strDeficiencyDate & ";" & strQuantity
-
varParameter = varParameter & ";" & strEmployeeIDFK & ";" & strCorrectedDate
-
-
If vbYes = MsgBox(strConfirmDelete, vbExclamation + vbYesNo, strConfirmDeleteTitle) Then
-
Forms!frmDeficiency.Visible = False
-
If IsNull(DLookup("EpisodeDetailID", "qryEpisodeDetail", strWhere)) Then
-
MsgBox strNullDelete, vbInformation + vbOKOnly, strNullDeleteTitle
-
Me.FormIDFK.SetFocus
-
Exit Sub
-
Else
-
DoCmd.OpenForm "frmDeleteCurrentRecord", DataMode:=acFormAdd, _
-
WindowMode:=acDialog, openArgs:=varParameter
-
End If
-
Else
-
MsgBox strCancelDelete, vbInformation + vbOKOnly, strCancelDeleteTitle
-
Me.FormIDFK.SetFocus
-
Exit Sub
-
End If
-
-
End Sub
-
And here's the code for the cmdSubmit on the frmDeleteCurren tRecord: -
Private Sub cmdSubmit_Click()
-
-
Dim varEpisodeDetailID As String, varPatientDetailIDFK As String, _
-
varFormIDFK As String, varDeficiencyIDFK As String, _
-
varProgressNoteIDFK As String, varDeficiencyDate As String, _
-
varQuantity As String, varEmployeeIDFK As String, _
-
varCorrectedDate As String, varAuditorFName As String, _
-
varAuditorLName As String, varReason As String, varDateDeleted As String
-
Dim nullErrorTitle As String, nullErrorMessage As String
-
Dim strConfirmDelete As String, strConfirmDeleteTitle As String
-
Dim strCancelDelete As String, strCancelDeleteTitle As String
-
Dim ctl As Control
-
Dim strDeleteRecordSQL As String, strLogDeletionSQL As String
-
Dim strDeleteReasonSQL As String
-
-
'Title for fields with null values
-
'------------------------------------
-
nullErrorTitle = ": Null Value"
-
-
'String for null values
-
'------------------------
-
nullErrorMessage = " cannot be blank. Please enter a value in this field."
-
-
'Test for null values
-
'-----------------------
-
For Each ctl In Me.Controls
-
If IsNull(ctl) And Not IsNothing(ctl.Tag) Then
-
ctlName = ctl.Tag
-
MsgBox ctlName + nullErrorMessage, vbExclamation, ctlName + nullErrorTitle
-
ctl.SetFocus
-
Exit Sub
-
End If
-
Next ctl ' End of null value test
-
-
varAuditorFName = Me.AuditorFirstName
-
varAuditorLName = Me.AuditorLastName
-
varReason = Me.ReasonDeleted
-
varDateDeleted = Me.DateDeleted
-
varEpisodeDetailID = Me.EpisodeDetailIDFK
-
varPatientDetailIDFK = Me.PatientDetailIDFK
-
varFormIDFK = Me.FormIDFK
-
varDeficiencyIDFK = Me.DeficiencyIDFK
-
varProgressNoteIDFK = Me.ProgressNoteIDFK
-
varDeficiencyDate = Me.DeficiencyDate
-
varQuantity = Me.Quantity
-
varEmployeeIDFK = Me.EmployeeIDFK
-
varCorrectedDate = Me.CorrectedDate
-
-
strLogDeletionSQL = "INSERT INTO qryDeletedRecordsLog ( PatientDetailIDFK, EpisodeDetailID, FormIDFK, ProgressNoteIDFK, DeficiencyIDFK, DeficiencyDate, Quantity, EmployeeIDFK, CorrectedDate ) " & _
-
"SELECT qryEpisodeDetail.PatientDetailIDFK, qryEpisodeDetail.EpisodeDetailID, qryEpisodeDetail.FormIDFK, qryEpisodeDetail.ProgressNoteIDFK, qryEpisodeDetail.DeficiencyIDFK, qryEpisodeDetail.DeficiencyDate, qryEpisodeDetail.Quantity, qryEpisodeDetail.EmployeeIDFK, qryEpisodeDetail.CorrectedDate " & _
-
"FROM qryEpisodeDetail " & _
-
"WHERE (((qryEpisodeDetail.EpisodeDetailID)= " & varEpisodeDetailID & "));"
-
-
strDeleteReasonSQL = "UPDATE qryDeletedRecordsLog " & _
-
"SET AuditorFirstName ='" & varAuditorFName & "', " & _
-
"AuditorLastName ='" & varAuditorLName & "', " & _
-
"ReasonDeleted = '" & varReason & "', " & _
-
"DateDeleted = #" & varDateDeleted & "# " & _
-
"WHERE (((qryDeletedRecordsLog.EpisodeDetailID)= " & varEpisodeDetailID & "));"
-
-
strConfirmDelete = "Are you sure you want to delete this record?" + Chr(13) + Chr(13) + "Warning: The action cannot be undone."
-
strConfirmDeleteTitle = "Confirm Delete"
-
strCancelDelete = "The delete operation has been cancelled."
-
strCancelDeleteTitle = "Delete Cancelled"
-
-
strDeleteRecordSQL = "DELETE * FROM tblEpisodeDetail " & _
-
"WHERE tblEpisodeDetail.EpisodeDetailID = " & varEpisodeDetailID & ";"
-
-
If vbYes = MsgBox(strConfirmDelete, vbExclamation + vbYesNo, strConfirmDeleteTitle) Then
-
DoCmd.RunSQL strLogDeletionSQL
-
DoCmd.RunSQL strDeleteReasonSQL
-
DoCmd.RunSQL strDeleteRecordSQL
-
CloseMe
-
'THIS IS WHERE IT WON'T UPDATE - Sorry for the all caps, just an attention-getter.
-
Forms![frmDeficiency]![fSubEpisodeDetail].Refresh
-
Forms!frmDeficiency.Visible = True
-
Else
-
Exit Sub
-
End If
-
-
End Sub
-
My intention is to have the delete command function just like the delete command on the toolbar, except for the fact that I need to go to another form real quick, have the user jot down some info, and then return to the updated subform.
It's late, so if this is unclear, please forgive me. I'll be happy to clarify if anything doesn't make sense.
Feb 15 '09
10 7174
Not sure if you guys got this resolved, but here's the solution: - Me.RecordSource = Me.RecordSource
-
Me.Requery
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Steve |
last post by:
I have several pairs of synchronized subforms in an application. I have a Delete
button for each pair that uses the following code or similar to delete a record
in the second subform:
DoCmd.SetWarnings False
DoCmd.RunCommand acCmdDeleteRecord
DoCmd.SetWarnings True
End If
ExitHere:
Me!SubName.SetFocus
|
by: Uwe Range |
last post by:
Hi to all,
I am displaying a list of records in a subform which is embedded in a
popup main form (in order to ensure that users close the form when
leaving it).
It seems to be impossible to delete a record in this subform.
When I switched modal off and tried to delete a record from the list,
I deleted a record on another form (below the popup form).
|
by: Maria |
last post by:
Is there another way to delete the current record in a subform from the main
form, another subform or a sub-subform other than setting focus on a field
in the subform and using run command acCmdDelete Record?
Thanks!
Maria
|
by: David Altemir |
last post by:
I have a button on "Form A" in the right margin of every record in my
recordset. When you click on a button, a dialog box ("Form B") pops
up that gives more details about that particular record.
The problem is that when I close the dialog, the cursor jumps to the
beginning of the recordset on "Form A". I want it to go back to the
record where I pressed the button.
What's the best way to set the focus to a particular record when...
|
by: MartinR |
last post by:
I would like to know the code that i should use to delete a record
without the message box saying "You are about to delete a record, are
you sure..." poping up.
At the moment i am using the code:
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
Any ideas to help me
| |
by: Steven |
last post by:
Hi,
Would need some thought about using a button of the existing form to search
record before deleting it.
Any quick help is very appreciated.
Steve
|
by: Phil Stanton |
last post by:
Deleting a record on a membership form. Does some VB checks to see if the
family are still in the list. Warns me there is no going back if I delete
the record, so I say OK and it appears to delete OK.
Record count goes down by 1, but if I select "ShowAllRecords", there he is
back and the recordCount back to the original value
Theories gratefully received
Phil
|
by: Constantine AI |
last post by:
Hi i am trying to DELETE a Record if the details do not exist within a table. Here is my code below;
Dim strSQL As String
Dim strSQL2 As String
Dim Reply As String
Dim db As Database
Dim rst As Recordset
Dim SeqItemNo As Integer
DoCmd.SetWarnings False
|
by: matthewslyman |
last post by:
I have an unusual design and some very unusual issues with my code... I have forced Access to cooperate on everything except one issue - record deletion.
My form design involves a recursively nested form. In other words, the form, m_settings_menueditor_recursive has a single subform; m_settings_menueditor_recursive (both are viewed as datasheets - so the form is its own subdatasheet.) The Form_Open event modifies the form's recordset so...
|
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...
|
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...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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...
|
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...
|
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();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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...
| |