Modules & VBA :: How To Build A Custom Record Delete
Sep 24, 2013
I'd like to override the default behaviour for deleting records in a form.Specifically, I want to build my own custom delete procedure so that when the user presses the Del button, my code fires to complete the deletion of the selected record(s). In order to do that, I'd set Allow Deletions = No for that form. I'd also want to code the KeyDown event for the Del key so that if record(s) are selected, my custom delete code fires, else the default behavior for the Del key happens.I'm primarily interested in how I might code the KeyDown event.
View Replies
ADVERTISEMENT
Jul 12, 2015
I am building a db for reservations for my limo company. I want to have a cmd button that verifies the user to make sure she wants to delete a run. This is what I have so far:
Private Sub cmdDeleteRun_Click()
Dim Response
Response = msgbox("Are you sure you want to delete this run?", vbYesNoCancel + vbCritical, "Really delete run?")
If Response = vbYes Then
End Sub
I don't know what I am missing for the cmd to actually delete it.
View 3 Replies
View Related
Jan 27, 2015
I have a custom record counter on a form using the below code:
Private Sub Form_Current()
If Me.NewRecord Then
Me.lblRecordCounter.Caption = _
"Record " & Me.CurrentRecord & " of " & Me.Recordset.RecordCount + 1
Else
Me.lblRecordCounter.Caption = _
"Record " & Me.CurrentRecord & " of " & Me.Recordset.RecordCount
End If
End Sub
I think at some stage the form was saved with a filter on and this may be causing the issue. The problem I have is:
There are 1749 records. Everytime I open the form the custom record counter displays "Record 1 of 501". The built in record counter shows 1 of 1749. The moment I hit the next record arrow the custom record counter displays "2 of 1749" and if I go back again it displays "1 of 1749.".
I know it's a filter causing the problem because I have a macro that does a clear search. As soon as I hit the clear search the custom counter goes back to "1 of 501" again (even though the built in one stays at 1 of 1749).
I have Filter on Load set to No.
what I am doing wrong?
View 13 Replies
View Related
Jul 11, 2014
To briefly explain my database; it is a bespoke referral management system within a hospital. Each record on the database contains patient demographic information, as well as information on their referral (i.e. date of referral, date of assessment, date of commencing treatment, discharge date etc.) Therefore, the same patient will appear multiple times in the database, with each separate record corresponding to a unique referral pathway.
The database forms are split to show patient information at the top, with referral information shown in a subform. I am trying to add navigation buttons to the subform that will allow the user to scroll through the referrals corresponding to the patient currently displayed on the main form.
Each patient has a uniquely identifiable number associated with them, and so it seems straightforward enough in my mind to have a button that will search for the record in the database where the patient's number matches the patient number of the current record, and where the referral date is minimum (for "First Referral"), maximum but less than current (for "Previous Referral"), minimum but greater than current (for "Next Referral"), and maximum (for "Last Referral").
View 5 Replies
View Related
Jun 28, 2013
When we browse through records in a subform we store the records in the database.When we want to delete a records for example the third record from the five records always the first records will be deleted. How can we delete the records where the cursor is at? When we are at the third record and press the delete button the third record from the list in the subform should be deleted.
Code:
Option Compare Database
Dim FocusBln As Boolean
Private Sub Identificeer()
Me.[Datum Aangemaakt].Visible = True
Me.[Datum Aangemaakt].SetFocus
If Me.[Datum Aangemaakt].Text = "" Then
[code]...
View 11 Replies
View Related
May 8, 2014
I have a form that opens up and fills in all of the Orders Table when it opens.
I then have a subform that is used to fill in the order details.
Currently if they open the form and then close it, it creates a record in the order table. I want to be able to delete this record if no information has been filled into the subform?
View 7 Replies
View Related
Jul 2, 2015
I have a form based on Table A. When a yes/no tick is clicked in the form, I want to delete a record from Table B. The tables are joined by ID numbers.
View 1 Replies
View Related
Oct 10, 2013
Table Name: Admin
Field Name: userid, admin (Y/N), Password, ConPw, PasswordReset (Y/n), Createdby
Trying to run a vba to find and delete records that was "createdby" the current user. Enviorn("username")
View 2 Replies
View Related
Jun 12, 2013
I am trying to create a query to find duplicates and delete the duplicates. The result will eventually be used in another query (append query) to update a table.I have a table with 4 columns lets say for simplicity they are A, B, C, D
I want my query to find duplicates within B and deleting them. The catch is before deleting them I need to look into column A to ebsure they are actually duplicates. Example below
Example
A B
John Doe Tires
John Doe Wipers
Allison Doe Tires
Allison Doe Tires
As you can see from the above Tires is a duplicate and need to be deleted.
A B
John Doe Tires
John Doe Wipers
Allison Doe Tires
View 7 Replies
View Related
Jan 12, 2014
For school I have to make a application in access how to delete a selected record in the table in a subform by using a button. The subform is in the main form and the button is also in the main form
View 14 Replies
View Related
Oct 20, 2014
If there a way i can remove duplicates from an email list? I pull these emails from a recordset. But i email may appear more than once and it doesn't look good e.g
johndoe@mail.com;johndoe@mail.com;jo...hndoe@mail.com.
I'd like to remove the duplicated email, if its possible. Code below.
Code:
Set rs = CurrentDb.OpenRecordset("select * from query")
With objMailItem
If rs.RecordCount > 0 Then
rs.MoveFirst
Do
If Not IsNull(rs![email]) Then
vRecipientList = vRecipientList & rs![email] & ";"
rs.MoveNext
Else
rs.MoveNext
End If
Loop Until rs.EOF
.To = vRecipientList
View 6 Replies
View Related
Jan 7, 2015
What is the correct syntax that would delete a file when the record is deleted. The file's path is listed in a record field, MailLocation. Every time I try this code, I receive an error!
I've tried the below, and number of iterations, including calling the killfile differently (me![MailLocation], me.MailLocation).
Code:
Private Sub Form_AfterDelConfirm(Status As Integer)
Dim KillFile As String
KillFile = me!MailLocation
Kill KillFile
End Sub
View 6 Replies
View Related
Jun 27, 2013
I have created a form and need to be able to delete employees from a table. I built a command button using the wizard and this is the current vb code-
Code:
Private Sub cmdDeleteEmployee_Click()
On Error GoTo Err_cmdDeleteEmployee_Click
DoCmd.RunCommand acCmdSelectRecord
DoCmd.RunCommand acCmdDeleteRecord
Exit_cmdDeleteEmployee_Click:
Exit Sub
Err_cmdDeleteEmployee_Click:
MsgBox Err.Description
Resume Exit_cmdDeleteEmployee_Click
End Sub
But when I click on the button I get a message saying it would create duplicate data in the table.
View 13 Replies
View Related
Jul 19, 2014
I am relatively new to VBA and have this loop (see below) was wondering if it was possible to build it into a variable, so I could call upon it within an IF statement.
Set ctl = Me.listSeeAllAssets
For Each varItem In ctl.ItemsSelected
rs1.AddNew
rs1!AssetNo = ctl.ItemData(varItem)
rs1!DateOfService = Me.DateOfService
[Code] .....
View 7 Replies
View Related
Aug 28, 2013
I am trying to build a new sql statement for a query using a string from items selected in a list box on a form. I have the string in place and keep getting syntax errors for the new sql statement. The code is below.
strSQL = " SELECT JG_tbl_LMEMP.DEPT_CODE" & _
" FROM JG_tbl_LMEMP" & _
" Group by JG_tbl_LMEMP.DEPT_CODE" & _
" Where JG_tbl_LMEMP.DEPT_Code IN(" & strCriteria & ")"
qdf.SQL = strSQL
View 3 Replies
View Related
Jul 9, 2014
I am trying to build an event when I double click a field. As soon as I click on Code Builder, access crashes. It does this with every access database I open.
View 14 Replies
View Related
Sep 9, 2013
I'm making an accounts package.
I've made a graph of revenue by customer but due to the number of customers it's a bit hard to see the customer names.
So I would like to be able to select my own custom group of 5 customers to plot on the graph.
To do this I think I need a query that selects the 5 customers which is populated from 5 comboboxes on a new form that the user can select customer names from but I'm not sure of the VBA that links all this together.
View 2 Replies
View Related
Jul 14, 2015
I have an endpoint for students so they can report any faults in the compound.I want to build a form that contains buttons of a certain value so that a student clicks on the button.Is fed directly to the table and pass to the next form to another value table.
View 7 Replies
View Related
Jul 9, 2014
I have a form with a sub form. when a record is choosen in a combo box the sub form is filled out with a record.
what I am trying to do is have a button that will copy that record to a history table then delete it off the the main table.
I cheated by using the wizard to get the code to delete the record but I am having troubles modifying the code to copy that record to the history table. Here is the code below. I have tried to insert code in several places but it just errors out.
'------------------------------------------------------------
' Master_tbl_sub_fm
'
'------------------------------------------------------------
Function Master_tbl_sub_fm()
On Error GoTo Master_tbl_sub_fm_Err
With CodeContextObject
On Error Resume Next
[Code] ....
View 8 Replies
View Related
May 19, 2011
I have two simple tables. I want to delete the records from Table1 that are on Table2. I've created a select query that gives me what I want but when I change to a delete query, I get this message: "Unable to delete from specified tables"
I think my problem has something to do with security but I can't figure out what to change.
View 13 Replies
View Related
Aug 7, 2007
I want to create a custom sequence when deleting a record but I'm having a problem.
What I want to do is prompt the user for the reason he/she is deleting the record and then archive this so it can be viewed in a log at a later time. This extra step is not as easy as I thought it would be.
What I did was put some coding into the On Delete event of the form. The code opens a form with a text box. The user can enter the reason for the delete in the text box and click OK or click cancel to abort the deletion.
My problem here is opening another form from the On Delete event. As soon as the form is open, the code just passes to the next step of the sequence and deletes the record.
There are 2 approaches that I've thought of but I'm not happy with either.
Approach 1:
In the On Delete event, set Cancel to True. That way the deletion is not handled by the delete sequence but rather by the new form that opens. The problem is that deleting a record from another form is not that simple. What I've tried is to execute a SQL statement that grabs the ID of the record from the open form and delete it. The problem is that although the record is deleted, all the fields on the form say #Deleted in them which is not that pretty. (Maybe there's some other way to do the deletion without this problem that I'm not aware of...?)
Approach 2:
Use an Inputbox. Unlike a custom form, the Inputbox delays execution of the code so the code can determine from the results (i.e. should it cancel the delete if the user clicked Cancel). The problem with Inputboxes is that they are not very flexible in the layout, they look pretty "packaged" (i.e. they look to me like the programmer didn't bother creating a means to enter a value). There's no way to place the buttons where you want or have it do better validation (e.g. I want the FORM to check that there's at least a few words describing why the user is deleting the invoice rather than have the form with the record get the input message passed back and then give an error and then pop open the Inputbox again)
I think that especially when you're creating an application with anything financial, you'll want to log a deleted invoice including the date, amount, possibly the client's name, invoice number, reason for deletion and the login name of the person doing the deletion. All of these are easy to record other than the reason.
Help would be much appreciated.
SHADOW
View 5 Replies
View Related
Sep 28, 2004
I have created a command button through the wizard that is basically:
DoCmd.GoToRecord , , acNewRec
Well, it puts all this code in the event:
Private Sub NewVerification_Click()
On Error GoTo Err_NewVerification_Click
DoCmd.GoToRecord , , acNewRec
InboundQuestions!Page1.SetFocus
VerificationNo.SetFocus
Exit_NewVerification_Click:
Exit Sub
Err_NewVerification_Click:
MsgBox Err.Description
Resume Exit_NewVerification_Click
End Sub
Well, my PK field is one users enter in manually (please don't ask why). What I need is something that checks to see if the number in that field is a duplicate key, so I can tell users via msgbox "Duplicate Number, try again". Right now, it's not that descriptive, it says "You can't go to the specified record". I guess all i need is an If statment, but I don't know the code that checks to see if [field1]'s value has already been used in my table. Any ideas?
View 4 Replies
View Related
Oct 20, 2014
My database has been set with the 'All records' locking option set to prevent two or more people editing files at once. This is working fine but I wondered if there is a way to make a more personal message appear instead of the default Access one, just to maintain a uniform look.
View 3 Replies
View Related
Dec 27, 2012
I would like to create a custom pop-up Message when one attempts to add a duplicate record.
Currently, I have a default pop-up message when you try to add a duplicate record. I set the field as Indexed= yes(No Duplicates) which generates a default pop-up message but it is technical and wordy. I would like to be able to simplify the wording to just let the user know not to add a duplicate record.
View 13 Replies
View Related
Jul 16, 2015
I have created 2 reports one that needs to be exported as an excel file and the other report as a PDF file. I have the exports working correctly for each on a button except this saves the files with the name of the report. The client wants the name of the file to appear as one of the fields on the report (the info that is in the description text box for example).
I have thought of two ways to do this and neither seems to be great - one is create a copy of the report with the new name and then export that saved file then delete the renamed report OR similar to that but instead rename the file save and rename it back (this causes all kinds of problems if the user cancels out that would need to be handled in the error handling - this is not a good way to go.
View 8 Replies
View Related
Jul 8, 2015
Ihave implemented custom events to sync between open forms. I noticed that if the code is engaging in middle of the way referncing a form with form constant (Form_formName) then the listeners stops listening so the event isn't firing, without getting the reason of this i just avoid using it Now, i have a problem that i want to open multiple instances of the same form and i didn't find another way than set frm = new form_formName as this is the only way i seem to be able to reference a closed form, so my question as followes
1. whether the "breaking" issue can be solved without avoiding "Form_FormName"
2. or a way to open
eference a form without using "form_FormName"
View 1 Replies
View Related