Modules & VBA :: Reset Autonumber Each Time Delete / Append Records In A Table?
Oct 25, 2013I need to reset the autonumber each time I delete/append records in a table. Best way?
View RepliesI need to reset the autonumber each time I delete/append records in a table. Best way?
View RepliesWe need to reset the autonumber after the last record is deleted.
For example:
2006
2007
2008
if 2008 gets deleted, we want the autonumber to reset back to 2008 rather than move to 2009.
Is this possible? This is the code we are using but cannot get the string to recognize the variable. If the variable is replaced with a number, it works, but it defeats the purpose of adding the plus 1 to the last autonumber.
Code:
Private Sub Command0_Click()
Dim RLMax As Integer
Dim Statement As String
RLMax = DMax("[id]", "Table1")
RLMax = RLMax + 1
strSQL = "Alter table table1 Alter Column Id Autoincrement(RLMax,1)"
DoCmd.RunSQL strSQL
End Sub
I realize we don't want to depend on the autonumber for anything other than a row identifier, but the table is setup that it is important for the rows to be sequential if the last record is deleted. Only if the last record is deleted.
I have a Microsoft Access database with SQL Server backend with 10000 records in my table, I have a autonumber field and in my database the purpose of the autonumber field is just to keep the record sequence (not to treat as a unique identifier) and I don't want to use a number field to manually enter the sequence. Whenever the record is deleted or the user won't save the record, it put gaps in the record sequence, Is there any way to refresh the autonumbers automatically "After delete confirm" event or "After Insert/update" even.
View 13 Replies View RelatedI have a table called "EquipmentRequired" which is populated by 4 append queries,
5000BaseReq, 6000BaseReq, 6000IFBBReq, EquipmentReq which get some of their information by counting fields in another table but all have the same field names.
The queries contain all data that is initially used to append new records to the table and this works fine.Unless some information changes or a record is added then I would like to add a button to a form and call it "update equipment" behind which would run a vba code firstly to delete all the records in "EquipmentRequired" table then run the 4 queries without the warnings and re-populate the table.
I don't know if this is the right place for my post. Since is in regard to queries...
I have data that I want to archive from one table to another table within a press of a button in a single form. The append work fine for me, but i tried adding the code to run the delete query to the same button as the append's one is, but giving me error that MS can't run the delete query because i have the form open exclusively. If I run the delete query with the form closed it work. How can I make the button to excute both append and delete queries at the same time.
Thanks in advance for the help
I have a table InvPrice and Updated Pricing
Need to delete all records from InvPrice that Match UpdatedPricing
InvPrice.StockCode = UpdatedPricing.StockCode
InvPrice.PriceCode = UpdatedPricing.StockCode
I have tried something like this...
Dim dbs As DAO.Database, sql As String, rCount As Integer
Set dbs = CurrentDb
sql = "DELETE * dbo_InvPrice Inner Join (dbo_InvPrice Inner Join UpdatedPricing on dbo_InvPrice.StockCode = UpdatedPricing.StockCode ) ON on dbo_INvPrice.PriceCode = UpdatedPricing.PriceCode "
dbs.Execute sql, dbFailOnError
I have a very simple 2010 Access database with only one table which contains a few fields (username, email, phone....)
I have a combobox with unbound controls to search/find users (by the lastname field). The combobox is in the header section which populates the fields (controls?) in subform below.
I have a delete button with some VBA code which allows the user to delete the currently displayed record however when the form refreshes, I end up with two issues:
1: I see #deleted# in the combobox dropdown until the dbase is closed/reopened (it's only typically used by one person at a time.) Compact/Repair doesn't seem necessary, especially since i think it's pretty difficult to do this programatically (?)
2: There are blank rows in the combobox dropdown from where the data used to reside after deleting the record.
I haven't been able to figure out how to remove those blank rows and refresh the combobox to display the remaining records (with the blank rows removed). So I have dozens of blank rows. Me.Requery doesn't seem to work.
My assumption is that the blank rows exist because I'm deleting the content from the combobox's initial creation?
Is there a better way to allow user's to see the list of user's and then be able to select that record and delete it?
If I use a simple search box on a form where people have to type a (last name for example), if it's spelled incorrectly, then nothing would be found.
I have two tables Table1,Table2. I want to delete records from Table1 whose ID= CoventionalID field value from Table2.
Table1 has two fields (ID,PolicyNumber)
Table2 has 5 fields(ID,PolicyNumber,ConventionalID,Conventional PolNo)
The following query doesn't delete anything.
Code:
DELETE *
FROM Table1 WHERE ID=(Select ConventionalID from Table2);
I have a form with a listbox that displays the name of a table. Once the listbox item is selected, the table name is set to a variable called myFile. I want append the records from the table (myFile) into another table.
View 1 Replies View RelatedI have a sub form that allows users to add staff to a project team, once added it populates a table which updates the subform showing the selected employee. I am trying to enable a delete function that allows users to remove an employee from the project team in the subform showing selected staff. Here is the code I have so far, but it doesn't work;
Code:
Private Sub Command4_Click()
Dim dbs As Database
Dim rs As Recordset
Dim sqlstr As String
Set dbs = CurrentDb
sqlstr = "DELETE tbl_CapexStaff.* FROM tbl_CapexStaff WHERE CAP_ID = Forms!frm_Switchboard.CAP_Live"
dbs.Execute (sqlstr)
End Sub
I have the field called subject_id which is autonumber in the form of 10001,10002,... And I want the field with the same format to appear in another table. But appending it leads to different numbering, i.e. the filed becomes 1, 2, ... instead of 10001, 10002 as I've formatted it in its original table. How could I append/copy such a field?
View 1 Replies View RelatedI am creating a database where the records of individual students are to be moved to different table depending on where they are in the graduation process. In order to do this, the secretary will enter the student in the "90 Hr Request" table (think of it as the first step), and move them down the line of tables (4 in total) until the final "Completed" table. Each table in the progression has more and more fields. However, a student (with their ID number as the primary key) can only be in one table at a time.
I understand this does not sound like a traditional database, as the data is not normalized. However, this is being used more as a filing system than anything else. Their data is primarily paper based (for legality reasons), but wishes to keep it organized in a database so they can run queries and print reports.
Currently, I am creating a macro that will run specific queries (in an order). I have made an append query that will move the records over, then I used a update (to null) and delete query combo to delete the old individual record. I made the delete + update query work by using a selected criteria.
How to make the append query move only one student's record at a time.
I need to extract a specific number of records into a table using a MakeTable or Append command using a temp variable, e.g. TempK&SA. Previously on the forum I was shown how code could be added to the OnOpen function to use a temp variable to select a specific number of records to report. ACCESS does not have the OnOpen function in the design view of a query like in the report. It does allow a SELECT TOP but only with fixed variables or percents (e.g. 25 in the code below).
The beginning code for the make table query (where 25 is the number of records added) is:
INSERT INTO [Output] ( RndNo, PointBiserial, BloomsTax, DateRevised, Exam1, Status, Exam2, Exam3, Exam4, [NCCPAKnowledge&Skills] )
SELECT TOP 25 TestBank.RndNo, TestBank.PointBiserial, TestBank.BloomsTax, TestBank.DateRevised, TestBank.Exam1, TestBank.Status, TestBank.Exam2, TestBank.Exam3, TestBank.Exam4, TestBank.[NCCPAKnowledge&Skills], *
FROM TestBank
WHERE (((TestBank.PointBiserial) Is Null Or (TestBank.PointBiserial) Between [TempVars]![TempPointBiserialLow] And .....
how to modify the code to allow a temp variable to determine the number of records to append to another table would be gratefully received. (This process then is repeated for a total of 7 append tables with different temp variables.)
Hi,
I have a autonumber function in my form, but i have deleted all the records and want to start again but the autonumber has not reset back to 1, is there a way to do this??
Thanks in advance.
I have an inventory split database. It has been working fine. I noticed when I try to enter a new record, it will not let me as it would create a duplicate record. It has actually started to use the autonumbers in the pk again reusing numbers that already exist starting at 1 and moving up sequentially.
How can I make it continue from where it left off or at least not duplicate any of the existing records. This database has many tables with a bunch of relationships.
Thanks!
Bill Hesson :confused:
just a small question. I have a database that assigns a unique 'audit id' to each entry. the ID is in the form of : DEA-[client prefix]-autonumber. Everything is working fine except the autonumber part. I have gaps in the numeric sequence. Ex: DEA-AAA-1, DEA-AAA-2, DEA-AAA-8, DEA-ABC17, etc.
is there a way that I can reset this autonumber so that it may look like this:
Ex: DEA-AAA-1, DEA-AAA-2, DEA-AAA-3, DEA-ABC4, etc.
Anyone know how to reset the autonumber for access ? Cox It keep running the number and I just seem can't make it back.
Also if there is some records which mistaken keyin I deleted it keep go for next new number. It would be a waste for that number.
:confused: :confused: :confused:
Is it possible to set autonumer to start from 1 again after all records in a database have been deleted?
View 7 Replies View RelatedI have two fields
1. Month (date field that shows only the current month only, ex: 04)
2. ItemNumber (created autonumber using =Dmax("ID","Table")+1 to retrieve the number from the previous record)
What I would like to do is everytime the current month changes I want the ItemNumber to reset to one.
I tried an If statement in the on current of the form
If Month <> Date() Then
ItemNumber = 1
Else
ItemNumber = Null
However it resets for every new record created, which by the code makes sense. Is there any way to have do this one time until the change of date or is there another way to go?
Hi I am trying to make a database, In which I have a table linked with the form.
There are two fields in the table 1.Serial Number & 2. Current Year
I want the serial No. field to be incremented after every record is added & Also the numer should start from "1" again as the Current Year Changes.
Can somebody help me in this.
I am learning new things in access & not that proficient. But i love to work in access.
So I have decided that I want my ID's to be AutoNumbers, but at the moment they are currently set as Numbers. I have already inserted data, to test, which has been deleted, however I am now unable to change the ID field back to AutoNumber.
How can I duplicate the tables so that this field can be changed again?
I have like 10 tables with heaps of feild, so remaking them will take long, but I know there is a way using queries, I am just not sure how...
I have a variable (dtDueDate as Date) showing as 6/28/2013. I want to append a time value to it (dtMaxTime as Date) which is 5:00 PM so dtDueDate reads 6/28/2013 05:00:00 PM. I have been going in circles trying to figure this out. My goal is to append this date to a table field which has a datetime (General Date).
View 6 Replies View RelatedIf I want to delete multiple records (select more than a record and right-click delete) how can I achieve this
given the following with one record:
Private Sub Form_Delete(Cancel As Integer)
DoCmd.RunSQL "Delete * from Trial where TrialID =(Text40)"
Me.Refresh
End Sub
PS:- I am trying to solve the cannot update /delete because of "modifications due to multiple base tables "issue and I am not sure if attempting to add in the On delete event would fix it (instead of an instead of delete trigger since it would be useless to setup triggers with one table to update ). I am thinking of doing the same with update in the after update event.
I have code that loops through a lot of objects, and adds them to a table. Right now I have suppressed the warnings via the DoCmd.Setwarnings = False command, in order to avoid the user seeing the message confirming that they want to make changes to the table.
However, I WOULD like them to see a warning if any of the table additions were unsuccessful for some reason. Is there a way to eliminate the user needing to confirm adding or modifying records, but NOT lose the warnings related to errors with adding these records? Even if it's a separate table that contains those warnings that they could look at afterward?
I'm using an append query that needs to add the records from another database into a table. I can get it to get the data and add the records. There are other columns in the database that are not in the one the data is pulled from. If I would run the append query again, it would add the same records again at the end. How can I avoid this? I only need to add new records that are not yet in the database I want to pull the records to.
View 4 Replies View RelatedI have a db using 3 large tables with 1:1 relationships. Before you question my normalization, I stress that these tables are strictly used to temporarily store user input information for a highly automated form with several hundred fields. All of the bound fields enable the form to be reopened and retain the information originally entered. The information is then transferred to a report and converted to a .pdf where it is filed; these 3 table's records are deleted weekly with a delete query. Other than a few combobox row source queries, these 3 tables are not connected to the rest of my db. At this point the form is functioning perfectly.
What I am trying to do is save about 3-5 of the partial (records) on 2 of these tables for indefinitely, no longer needed, or overwritten. Reason being is that partial information (records) on this form can be recalled and duplicated into a new form, saving the user time from having to completely re-enter some fields that will not change week to week.
So far, my best idea is to have 2 duplicate tables that store these records (based on a checkbox on a scheduled query event) that can be recalled and written back into the 2 main tables with a new primary key when needed. Append queries only work with one table at a time, and I need to maintain the integrity of these records 1:1 across the 2 tables with their primary keys intact.