Modules & VBA :: Reset Autonumber And Keep Sequence After Deleting Record

Feb 28, 2014

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 Replies


ADVERTISEMENT

Modules & VBA :: Reset Autonumber After Record Deletion

Jul 16, 2015

We 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.

View 12 Replies View Related

Deleting The Last Record Where Key Is Autonumber

Nov 3, 2004

I have a situation where I need to delete the last record I entered.

This is the sequence

1. The user selects that they want to add a new record (customer order)
2. I (using a macro) append a new record with some information filled out. This is shown in an input form (with lots of other info displayed) and I save the autonumber key to an invisible text field.
3. The user can then either SAVE or CANCEL. In the cancel I need to delete the record that was just added (see step 1.)

The problem is I need to close the form before I delete the record (thus removing the invisible text field containing the key to the newly created record). Once I close the form I don't know how to determine which record to delete (since I no longer know the Key) and I can't delete the record while the form is open since it is locked.

I am probably not doing this incorrectly but my issue is:

How do I delete (using SQL) the latest record an individual has created (which will always be the highest autonumber Key with the userID equal to this users's ID)?

Any ideas????

Thanks

View 1 Replies View Related

Modules & VBA :: Reset Autonumber Each Time Delete / Append Records In A Table?

Oct 25, 2013

I need to reset the autonumber each time I delete/append records in a table. Best way?

View 5 Replies View Related

Forms :: Deleting Record When Closing After Autonumber Has Been Incremented

Oct 15, 2014

I have a form that I want to open on a new record (with an Autonumber-based ID string that is a calculated field) and this uses a hidden field in the form when it opens to spawn a new record, ready to be related to some additional items in a join table. The user selects those from a list box.I want to add a "return to main menu without saving" button, but not matter what code I use, it obstinately continues to save the record.

Code:
DoCmd.Close acForm, "JobPlanfromCAFs", acSaveNo
on the command button - no effect.

I also tried this code on the form's BeforeUpdate method. No effect. The new record continues to exist.

Code:
If Not (Me.NewRecord) Then
If MsgBox("Would You Like To Save The Changes To This Record?", vbQuestion + vbYesNo + vbDefaultButton1, "Save Changes to Record ???") = vbNo Then
Me.Undo
End If
Else
If MsgBox("Would You Like To Save This New Record?", vbQuestion + vbYesNo + vbDefaultButton1, "Save This Record ???") = vbNo Then
Me.Undo
End If
End If

I suppose I can 'query out' incomplete records at other places in the database, but it's annoying to not be able to return to the same JobID again if you don't save it.

View 1 Replies View Related

Queries :: Sequence Number Reset At Each ID Exchange

Nov 18, 2014

I have two tables - one with parent Records, the other with child records. The ID links the two tables .I want to add a sequence number on the child table which resets at each ID change. What would be the best way to accomplish this?

Code:
PC_ID ID Name Address

P 1 Parent1 Address1
P 2 Parent2 Address1

PC_ID ID Name Address SEQ

C 1 Child1 Address1 1
C 1 Child2 Address1 2
C 1 Child3 Address1 3
C 1 Child3 Address1 4
C 2 Child1 Address1 1
C 2 Child2 Address1 2
C 2 Child3 Address1 3

View 4 Replies View Related

Auto-Sequence Number When Deleting Field Midpoint

Nov 21, 2011

At present I am running Revit Architecture with DBLink to access to edit fields for shelving etc.

What i am doing is fitting out warehouses with 600+ shelving units and they are all numbered.

These numbers are tagged in the drawing.

What I am hoping to do is export the data to access (completed) then amend any changes within access.

Normally, we would put say 600 shelving units on a drawing all tagged 1-600. But then the client may want to delete shelving unit 321.

Leaving the drawing with all shelving units tagged 1-320,322-600.

How would i go about it so access renumbers all data after the deleted field (ie number 321)?

View 2 Replies View Related

Autonumber Column Not In Sequence

Aug 15, 2007

Hi,
Its good to be back after a long time. Hope everyones fine.
I have a query and would appreciate any help.

I have a master-table (tblM) and two related tables (tbl1, tbl2) with one-to-one relation.

Relation1 : tblM.ID (autonumber) related to tbl1.caseID (number;LongInteger)
Relation2 : tblM.ID (autonumber) related to tbl2.caseID (number;LongInteger)

Relations are cascaded (referential integrity imposed).

I import data from excel and feed fields of tblM (I dont feed ID field from excel as it generates autonumber). At a time I feed 150 records (daily).

I have a front-end based on query from three underlying tables. Data-entry-operators do not work on tblM data as it is readonly in the front-end. They enter data in the tbl1 and tbl2 columns.

I noticed as they start entering data in tbl1 columns, the tbl1.caseID column gets data from tblM.ID on its own. Same happens in the case of tbl2.

My observation is :
I find that tblM.ID is not equal to the number of records available in tblM. (ie tblM.ID is more/less than number of records in the table. So the tblM.ID generated is not in serial.

Next time as I start importing data from excel file to tblM it gives me error and not allowing further import.

Any help!

Thanks and regards,
Prodigy.

View 5 Replies View Related

Autonumber Reset

Nov 1, 2005

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.

View 5 Replies View Related

My Autonumber Has Reset To 1 ?

Oct 20, 2005

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:

View 3 Replies View Related

Reset Autonumber

Jul 29, 2005

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.

View 2 Replies View Related

How To Reset AutoNumber

May 18, 2006

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:

View 8 Replies View Related

Reset Autonumber

Mar 28, 2006

Is it possible to set autonumer to start from 1 again after all records in a database have been deleted?

View 7 Replies View Related

Numbering Sequence/Autonumber Problem...

Jun 7, 2006

I need to create a button that generates a sequential four digit requisition number and places that number in a field along with some text. I cannot use autonumber because this number is not and cannot be the primary key. In addition, I need to be able to reset the number to 0001 at the beginning of each federal fiscal year. Here are the details:

reqtype: An option group that has these choices: PC, TL, and RQ
actionyear: A drop down box that lists the current fiscal year: 2007
reqnumber: A field that, when the button is clicked, combines a text prefix, reqtype, and actionyear with a four digit sequential number.

The end result should look like this: SEC-07-PC0010 and be recorded in the reqnumber field.

My code writing abilities are limited. Could someone please help me out. Thanks.

View 1 Replies View Related

Reset Created Autonumber

Jan 28, 2005

I 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?

View 2 Replies View Related

How To Create Reset A Autonumber After Every Year

Feb 18, 2007

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.

View 11 Replies View Related

Modules & VBA :: Event Information - Deleting Record Creates A Blank Record

Sep 8, 2013

I have a form set to the table Client Information with a subform set to the table Event Information. Client Information has a one to many relationship to Event Information.

There is a button that deletes the current record in Client Information--also deleting the related records in Event Information--then closes the form. The code works fine but a blank record in Event Information is apparently being created before the form closes.

Here's the VBA that I'm using:

Private Sub CmdDelReturn_Click()
Dim CmdDelReturnMsg As String
CmdDelReturnMsg = MsgBox("Delete event & client then return to front?", vbYesNo + vbDefaultButton1, "Delete and Return?")

[Code] ....

It's not a big deal because the button won't be used often and I can manually go into the table to delete the blank record. But if there's a simple solution to prevent this that would be nice.

View 3 Replies View Related

How To Reset Tables To Change Data Type From Number To Autonumber

Dec 4, 2013

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...

View 2 Replies View Related

Modules & VBA :: Deleting Only One Record?

Apr 3, 2014

How do I delete only one record in a table that has duplicate records using SQL?

Code:
DELETE tblTemp.Fruit, tblTemp.[Country of Origin], tblTemp.Qty, tblTemp.Date, tblTemp.Currency
FROM tblTemp
WHERE (((tblTemp.Fruit)='Fruit') AND ((tblTemp.[Country of Origin])='Country of Origin') AND ((tblTemp.Qty)='Qty') AND ((tblTemp.Date)='Date') AND ((tblTemp.Currency)='Currency'));

View 10 Replies View Related

Modules & VBA :: Deleting Record From Table Or Query

Feb 20, 2014

I am trying to delete a record from a table and when I pass the variable as a text value it works but when I pass as a number I am getting a mismatch error.

I have to use it as a number as I am doing other update code in my database and it is a number.

Code:
DoCmd.RunSQL "DELETE * FROM TblIssueData Where tblIssueData.SerNum = ' & Me.txtserNum & ';"

When I am using TblIssueData SerNum as a text variable in table it works but when I specify SerNum as a number in the table it gives me data mismatch error. I have to leave it as a number for other VBA code in my database. I believe it is just a syntax error but not sure where to go with it.

View 2 Replies View Related

Deleting Records And Autonumber ??

Jan 25, 2006

quick question guys...

if i have a sales order that the sales order # is an autonumber and i manually delete the records my next new record still follows the last number i had before that is now deleted..

example

sales order 1001
sales order 1002

if i delete all the records on the table and clean it all out

the next new autonumber will be 1003...

i want it to be 1001 again...
and yes its set to an index of no dups

View 1 Replies View Related

Deleting Records And Autonumber ??

Jan 25, 2006

quick question guys...

if i have a sales order that the sales order # is an autonumber and i manually delete the records my next new record still follows the last number i had before that is now deleted..

example

sales order 1001
sales order 1002

if i delete all the records on the table and clean it all out

the next new autonumber will be 1003...

i want it to be 1001 again...
and yes its set to an index of no dups

View 1 Replies View Related

Modules & VBA :: Deleting Record And Then Delete Listed File?

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

Modules & VBA :: How To Get Autonumber ID Before Update / Save Record

Mar 27, 2015

I wanted to get the autonumber ID before a record was saved to the table. My fields are on a form that is linked to the table. Maybe my solution is not the most elegant but it seems to work.

I messed around and came up with this solution: it creates the next record and captures the autoID then increments it and creates the record we will actually use. Since we know the current autoID we know 100% the next will be the current+1

Code:

' Code by Witchcraftz
' Button event to add new record
Private Sub cmdAddRecord_Click()
Dim strID As String

[code]...

View 2 Replies View Related

Modules & VBA :: Duplicating Record With Autonumber Field

May 23, 2015

I am wanting to create a new record in a table copying the majority of the data from another record in the table. I am using the following code which creates new records but the data isn't being copied.

This is the section of code:-

' Return Control object variable pointing to list box.
Set ctlList = Me!lbStudents
' Enumerate through selected items.
For Each varItem In ctlList.ItemsSelected
' Get the info to get the enrolment record
intClientID = Me.lbStudents.Column(7, varItem)

[Code]...

what I'm doing wrong?

View 2 Replies View Related

Deleting All Related Sub Records When Deleting The "main" Record.

Apr 12, 2008

I have two tables.

1. Persons (list of persons)
2. Job history (list of jobs)

each person have their own job history. all these jobs are stored in the job history table. when i delete a person i would like the job history for this person deleted as well. each job stored in the job table have a field with person name, so that it is linked to this person.

how can i do this? vba or simple properties options?

- Roy

View 1 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved