Modules & VBA :: Adding Record To A Table - Closing A Form Without Saving
Nov 26, 2013
I have a form to add a record to a table. How can I give the user a way to close this form without saving the just created record.
I tried
If me.dirty then
DoCmd.RunCommand acCmdDeleteRecord
endif
This works, but gives a messagebox in return to confirm the command, and I don't want that. And I try to avoid sendkeys. I also don't want to change the options of access.
I have a popup called by a subform to add a new record or edit a selected record. I keep getting "Runtime error 32502". The value you entered isn't valid for the field "|"
I have no required fields and all the drop down related fields have the right value type in them (That I can find)The only "|" reference I can find is in the OpenArgs content below when I load the form. If I'm adding a new record I pass two fileds via the OpenArgs
Private Sub Command52_Click() DoCmd.OpenForm "AddDebtorPaymentFrm", , , , acFormAdd, OpenArgs:=Me![DebtorId] & "|" & Me![MatterId] End Sub
or if I'm modifying a record from the subform on click I
Private Sub Text38_Click() DoCmd.OpenForm "AddDebtorPaymentFrm", acNormal, , "[Transactions].[TransId] = " & Me.TransId, acFormEdit End Sub
Below is the Popup Load code
Private Sub Form_Load() If Me.DataEntry = True Then Me.VariableHeading = "Add A Debtor Payment"
I am trying to open a form in design mode and add controls, this i have done. I am doing this all in a class, and am having trouble saving the modified form.
I have tried using the following, both produce errors
I have a form I would like to close without saving the record using a button. here is the code I have but it closes the form and it also writes the record to the table.
Code: Private Sub ClosewoSave_Click() Cancel = True Me.Undo DoCmd.close DoCmd.OpenForm "frmMenu" End Sub
I found in a thread that Cancel = True would not write the record.
I need to save a single record (preferably the current record) as a PDF. I have created a form for my boss to calculate bids. He wants to save each record individually as a PDF to upload into our service software program to attach to client files. I can save a selected record as a PDF if I print the selected record first. We need to eliminate having to print it first as it is just a waste of paper and an unnecessary step. I am kind of thinking that VBA and attaching that to a control button on the form is the way to go, but I am new to writing code and I am completely confused!
I have a timer form which closes the database after a period of time with DoCmd.Quit. Another form is open at this point but if a user has left it in the middle of editing it I want to be able to save the record in the other form and close it before the timer form closes the database.
What VBA do I need in the timer form to save the record and close the other form before DoCmd.Quit? Just to be clear the code is...
Private Sub Form_Timer() On Error Resume Next Me.Tag = Val(Me.Tag) - (Me.TimerInterval / 1000) Me.Caption = "The database will exit in " & Me.Tag & " seconds" If Val(Me.Tag) <= 0 Then
I am currently working on an Access Database that houses our security clearance information. Most of the system is up and running but the most recent form has got me spinning my wheels. I have a Word User Form that users will download and complete, once completed the macros will automatically send us the document to be added to our database. Most of this is working the problem is that this portion of the database has multiple related tables and at any given time a user may require multiple records in the related tables. I have created the code to copy most of the information but am getting stuck adding a new record on the sub-form when multiple items are required. Here is a breakdown of the scenario
Word Doc Table 1 = Basic Organization Info Word Doc Table 2+ = Sites to Visit (There could be more than 1 table added here) Word Doc Table 3+ = People to go on site (this might not be the third table based on user interaction for sites)
So far I can get Table 1 and Table 2 data but if there are more than 1 site I cant seem to get the system to create a new record on the related table it is creating a new record on the main form. Here are the lines I used to try to create the related record..
When I put just the above code on a button it seems to have worked as the sub-form showed an additional record was created but when using this on my macro the sub-form is not taking the focus for some reason.
In one form, I have to click on button that opens the other form. Each form is bound to its table and those two tables are linked by Primary [RaDAR_Id] and Foreign [radar_id] fields. I would like the code to:
* open the other form * move to the first record that has [radar_id] = [RaDAR_Is] if exists
If there is no any record in the other form that contains [radar_id] = [RaDAR_Id] then I want to create such record. So I am using the code (below). The problem is that the other form is not being updated.
Code:
Private Sub cmd_edit_usage_Click() ' DoCmd.OpenForm "frm_edit_usage" Dim lngRadarId As Long Dim patientId As Long Dim rsUsage As DAO.Recordset Dim rsUsageWrite As DAO.Recordset
I have a form for entry and some fields are computed or result of a query from another table. I have a function that looks up a value from another table like so
************************************************** ******** Public Function GetTargetType() As Variant GetTargetType = DLookup("type", "tblFormulations", "[tblFormulations!formulation]=Forms![frmNmsConsumptionEntry]![formulation]") End Function ************************************************** ********
Which works fine when I test in the immediate window.Then I have this form event. This however does not insert this value when I am adding records using my continuous form.
************************************************** ******** Private Sub Form_BeforeInsert(Cancel As Integer) Me!target_group = GetTargetType() 'Forms!frmNmsConsumptionEntry!target_group = GetTargetType() '[tblNmsConsumption.target_group] = GetTargetType() End Sub ************************************************** ********
making sure I can insert this value once retrieved.
I have limited experience in Access, but I have managed to create a user form, where items are selected from comboboxes (Test results; when, who, outcome, etc)
At the end I have built in a command button that should add a record to an existing table, but so far no luck. I have used the following VB code for this:
Private Sub Save_test_results_KeyPress(KeyAscii As Integer) Dim dbsICT_Test_Management As DAO.Database Dim rstActual_test_results As DAO.Recordset Set dbsICT_Test_Management = CurrentDb Set rstActual_test_results = dbsICT_Test_Management.OpenRecordset("Actual_test_ results")
rstActual_test_results.AddNew rstActual_test_results.Update End Sub
Whenever I add a new record to a table with a form I created, it records the "ID autonumber" that it's associated with instead of the text. For instance, if I selected "Kevin" from a combobox list and had the form record it, it will show up as "1" in the table under the field name "Names".
I have a table with 2 fields in it - Type and Pallet_Case - using a form the user enters the name of the Type and then from a combo box selects either Pallet or Case. There is a button on the form that is to save the new record to the table. (code below) The strangeness that is happening is that when the new record is added to the table, whatever is the first existing record alphabetically in the table is changed to the same Pallet_Case selection that was made for the new record.
I have a list box that displays on the form that is updated after a new record is added to show what records exist in the table (this is done by a query of the table and sorts on the type), so I can see this happening without having to open the table. It doesn't matter what sort order I put the list box in nor the table it still changes the first record alphabetically. And it is only change the Pallet-Case field. I even changed the first record to something else and it still did this.
Dim dbs As DAO.Database, strSql As String Set dbs = CurrentDb strSql = "Insert into [PP Type TBL] ([Prepack Type],[Pallet Case]) Values ('" & Me.Type & "','" & Me.Pallet_Case & "' )" dbs.Execute strSql, dbFailOnError
I have a form with 55 values entered. On closing the form, I need it to decide if this is a new record. If it is a new record, it loads all 55 values into an array. If all values are above 20,000, it goes ahead and closes the form. If any are below 20,000, it writes the record to another table and brings up that form to add add a comment.
Every thing does as it should except determining if it is a new record. What property will trigger it properly? All the properties I have tried either triggers it on all the records (even if it is an old record) or it does not trigger it and closes without prompting the code.
I have a form that has some fields with validation rules, which are Not Is Null. I have a private function to validate records (here is a snipet)
Code: Private Function ValidateRecord() As Boolean ValidateRecord = False Select Case Outcome Case "Interpretation" If IsNull(Me.[Date Provided]) Then MsgBox [Date Provided].ValidationText Exit Function End If
[code]...
The form has a save and close button. I was wondering if there was a way to keep the form from closing if those fields are null. Right now, you click the button, the validation text pops up (it pops up twice too), and then the form closes.
I thought about maybe having the (If...Then, Inputbox)code in the Form_BeforeUpdate instead. If I do that, is there a way to do that for date textboxes and comboboxes where you choose the value instead of typing it?
I have a statistical program and the user constantly use the form to check calculations and get out without saving a record. In order to allow this with out writing to the table I used unbound fields and an accept and close command buttons.
This worked well until I added a subform to one of the forms. Now, if I just open that form and then click the close button, I get a blank record in the table associated to the main form. Is there a way to stop this?
I have a form (frmAuditEntry) that includes a subform (sfrmAuditDetail). The user will enter audit information on the subform. There is a check box on the subform to identify containers that had errors in selection. When the box is check by the user, a pop up form opens where the user can enter the details regarding the type of error. The audit number and the container ID are carried over from the main form to the pop up form to link the information.
This is the code I have in the AfterUpdate event of the checkbox:
Private Sub Errors_AfterUpdate() Dim rs As Object Dim strBookmark As String strBookmark = Me.ContainerID Me.Requery
[Code] ....
This works great and keeps the focus on the record the user checked having errors so the right information transfers tot he pop up form fields. When the pop up form is closed, the focus goes back to the subform but keeps the focus on the container ID control of the record that the user previously checked as having errors (hope that makes sense).
What I would like to happen is this: When the pop up form is closed, I want the focus to go back to the subform but to go to the last blank record on the subform (if the user moved off the record before checking the error checkbox) or go to a new record (if the user did not move to a new record already before checking the error checkbox).
I currently have 3 forms open and when I call a specific function and it gets to this line below it goes to the on close of 1 of my open forms closes that form before it opens the selected form in code (below) in design mode. It doesn't close all my forms....why does it do this?
I have a field on a form [vin] that is based on a table, except i changed control source to a Dlookup to pull the vin number in from another table so i wont have to type it when i enter the record. However, this field is not saving when i save the record. I cannot just make a relationship because we reuse the same vehicle numbers, when we sell van 1 with vin 123, and replace it with a new van with Vin 456, we still call it van 1, so the unique vin is the only way to distinguish the two.
Private Sub Command79_Click() On Error GoTo Err_Command79_Click 'the following code is supposed to warn the user if there is no STOP filling time for each START filling time before the main form is closed
If [Text344] > #12:00:01 AM# Then If [Text365] >= [Text344] Then
I have a "Search" form that I am using to search through a query in a list box of all of my Customers. Once the record that I am wanting to view comes up I highlight it and click a "View" button to bring up another form with the customers full record. When this form is open I am able to update the customer information and add User's to it if necessary.
My problem comes after I click on my save and close button that takes me back to me search form. I want to close the search form and the error I get is "The record cannot be deleted or changed because table "tblUserProfile" includes related records." I click OK and get a SECOND error stating "You can't save this record at this time. MS Access may have encountered an error while trying to save a record. If you close this object now, the data changes you made will be lost. Do you want to close the database object anyway?"
I have already made my changes and saved them in the form with the customer record so am not sure why I am getting an error when trying to close the Search form.
I am trying to find out what VBA Code I should use for a way to save a main table name: Master_Template on a certain day of the week (weekly) to happen automatically on close of the database - of course on that certain day of the week.
Hello, I have a form and I have a button so people can open records to load into the form. The problem is that whenever they close the form it updates the information in the table. How do I stop that from happening? I want the information in the table to update only when they hit the button I made (which works).
And how do I stop it from loading the record when I open the form, or maybe I can specify to load a blank record instead, how do I do that?
I've got this form called mainmenu and inside this form I've got this code to prevent it from being closed.
Code: Private Sub Form_Unload(Cancel As Integer) Cancel = True End Sub
Now then, when I try to switch to design view in this form it doesn't let me because of this code. Is there anyway to tweak this code so that I can get into design view without having to keep disabling it?
Can anyone guide me to how to code a form that will not error when closed if nothing has been input to the first field which has the focus? I have a start up form that has fields connected to a table and if this database is open and the user desides not to use it then closes it without entering any data it will error. Is this a recordset issue? Thanks
I got an error msg on form with closing. I have a main form (SalesReturnOrDamaged) and subform (SalesReturnOrDamagedSubform).
i have used a VBA code on main form Close Command button as per shown in Code Tag. But that is not working and shown an error msg as per screenshot. how to change that VBA code for empty form close without save the record?
Code: Private Sub Close_Click() On Error GoTo Err_Close_Click If Forms![SalesReturnOrDamaged]![SalesReturnOrDamagedSubform].Form![ItemCode].Value = "" Then Forms![SalesReturnOrDamaged]![SalesReturnOrDamagedSubform].Form![Product].Value = "" Forms![SalesReturnOrDamaged]![SalesReturnOrDamagedSubform].Form![MRP].Value = 0 Or ""
I have several Access DB's that I work with and all of them have a close option(x in the upper right corner) on forms/tables/queries except for one. This is one that I did not create. So, when I open a form in design view to modify it, the only way to close it is to close down the DB?