473,394 Members | 1,946 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Access creating its own IDs.

111 100+
I have an access database which has a table called Class.It has a column called ID, which is Text and it is an Automatic entry of an ID number to uniquely identify the line of data. The field size is 12, for ex: 11-136,11-137...
It is acting weired lately and changing the IDs of existing records.
I have attached a file which shows the problem.
Thanks!!
Attached Images
File Type: jpg IDChange.jpg (10.0 KB, 183 views)
Jun 16 '10 #1
19 1659
patjones
931 Expert 512MB
I can't get your image to show any larger than thumbnail size. Can you try re-posting it at a larger size? I'd be happy to take a look at it if I can view it.

Pat
Jun 16 '10 #2
AccessBeetle
111 100+
Please try to save it first and then open it in Paint. May be that opens a larger view.
Let me know if you are able to view it.
Thanks
Jun 16 '10 #3
AccessBeetle
111 100+
Here is the another image.
Jun 16 '10 #4
AccessBeetle
111 100+
Here is the another image
Attached Images
File Type: jpg IDChange1.jpg (20.9 KB, 154 views)
Jun 16 '10 #5
patjones
931 Expert 512MB
Paint is what I tried first but it is showing as a thumbnail...
Jun 16 '10 #6
patjones
931 Expert 512MB
When a new record is created, where does the ID come from? Also, does this happen to random records or does it happen only to records that have been edited?

Pat
Jun 16 '10 #7
AccessBeetle
111 100+
@zepphead80
Were you be able to see the image?
There is a chunk of code written to increment that ID number.
Expand|Select|Wrap|Line Numbers
  1.  Me![ID] = Me![COUNTY] & "-" & (mx + 1)
This started to happen suddenly. I mean it was working fine untill somebody pulled a report and tried to compare it with old one, this glitch was found.
This happens randomly. No specific number of records, No certain range. I also tried to compact and repair but still doing it.
Jun 16 '10 #8
missinglinq
3,532 Expert 2GB
This still doesn't tell us much! What event is the code in? Where does mx come from?

Linq ;0)>
Jun 16 '10 #9
patjones
931 Expert 512MB
I guess what I'm trying to determine here is exactly what action causes these changes to occur. You know quite specifically that 11-176 used to be 11-140...so what happened in between? Was it running the report that caused the change?

And as missinglinq points out, we'd need a little more code to really analyze how you are putting these ID's together.

Pat
Jun 16 '10 #10
AccessBeetle
111 100+
@zepphead80
It is the whole code. It is little bit long. I didn't know where to cut it from so
Expand|Select|Wrap|Line Numbers
  1. Private Sub COUNTY_LostFocus()
  2.  
  3. Dim db As DAO.Database
  4. Dim mx As Integer
  5. Dim rsCo As DAO.Recordset
  6. Dim rsVal As String
  7. Dim rsCoVal As Integer
  8. Dim strSQL As String
  9.  
  10. Set db = CurrentDb()
  11.  
  12. rsCoVal = Me![COUNTY]
  13.  
  14. strSQL = "Select Class.ID from Class where Class.County = " & rsCoVal
  15. Set rsCo = db.OpenRecordset(strSQL)
  16.  
  17. If rsCoVal <= 9 Then
  18.         If rsCo.RecordCount > 0 Then
  19.             rsVal = rsCo.Fields("[ID]").Value
  20.             ' Set mx equal to the numeric portion of the field.
  21.             ' Change the below number of 0 to strip the first couple
  22.             ' of bits as needed.
  23.  
  24.             mx = Abs(Right(rsVal, Len(rsVal) - 2))
  25.  
  26.             ' Loop to make sure you have the maximum number.
  27.             Do While Not rsCo.EOF
  28.             rsVal = rsCo.Fields("[ID]").Value
  29.             ' Change the below numbers of 0 to strip the first couple of
  30.             ' bits as needed.  Must be the same as your changed above.
  31.                 If Abs(Right(rsVal, Len(rsVal) - 2)) > mx Then
  32.                     mx = Abs(Right(rsVal, Len(rsVal) - 2))
  33.                 End If
  34.                 rsCo.MoveNext
  35.          Loop
  36.     Else
  37.         mx = 0
  38.     End If
  39.     'Increment the maximum value by one and
  40.     'combine the text with the maximum number.
  41.  
  42.     Me![ID] = Me![COUNTY] & "-" & (mx + 1)
  43.  
  44.         rsCo.Close
  45.         db.Close
  46.  
  47.     Set rsCo = Nothing
  48.     Set db = Nothing
  49.  
  50. ElseIf rsCoVal >= 10 Then
  51.  
  52.     If rsCo.RecordCount > 0 Then
  53.         rsVal = rsCo.Fields("[ID]").Value
  54.  
  55.         ' Set mx equal to the numeric portion of the field.
  56.         ' Change the below number of 0 to strip the first couple
  57.         ' of bits as needed.
  58.  
  59.         mx = Abs(Right(rsVal, Len(rsVal) - 3))
  60.  
  61.         ' Loop to make sure you have the maximum number.
  62.         Do While Not rsCo.EOF
  63.         rsVal = rsCo.Fields("[ID]").Value
  64.         ' Change the below numbers of 0 to strip the first couple of
  65.         ' bits as needed.  Must be the same as your changed above.
  66.             If Abs(Right(rsVal, Len(rsVal) - 3)) > mx Then
  67.                 mx = Abs(Right(rsVal, Len(rsVal) - 3))
  68.             End If
  69.             rsCo.MoveNext
  70.         Loop
  71.     Else
  72.         mx = 0
  73.     End If
  74.         'Increment the maximum value by one and
  75.         'combine the text with the maximum number.
  76.  
  77.     Me![ID] = Me![COUNTY] & "-" & (mx + 1)
  78.  
  79.     rsCo.Close
  80.     db.Close
  81.  
  82.     Set rsCo = Nothing
  83.     Set db = Nothing
  84.  
  85. Else
  86.     MsgBox "An error with the automatic filling of the ID number.", vbOKOnly
  87. End If
  88.  
  89. End Sub
Jun 16 '10 #11
AccessBeetle
111 100+
I hardly have doubt that it is gone like that due to just running the report. It is the daily procedure. I mean it is not follwoing any partucular pattern.
Jun 16 '10 #12
gershwyn
122 100+
What is the county control and how is it used?

It looks to me that whenever the user leaves the County field (since this code is in the LostFocus event) the code calculates the new ID code and assigns it, which is probably not what you want. I would put a check at the beginning of the code to determine whether or not a new ID is needed, but what I don't know is how to determine that.

Can the county be changed after the ID is assigned the first time? And if so, what should happen?
Jun 16 '10 #13
AccessBeetle
111 100+
@gershwyn
Expand|Select|Wrap|Line Numbers
  1.  I would put a check at the beginning of the code to determine whether or not a new ID is needed, but what I don't know is how to determine that.
  2.  
  3. Can the county be changed after the ID is assigned the first time? And if so, what should happen?
Yes, County can be changed while entering the record but not after the user has clicked on "Next" record. I put the break in the begining of the code and tried to enter a new record. When I tried to change the county multiple times, it was assigning the ID based on the county I select from the dd. But I would sure like to put a code that checks existing IDs. Give me some input on that.
Thanks
Jun 17 '10 #14
patjones
931 Expert 512MB
@AccessBeetle
Can you post the code which actually commits new records to the table? In the code you posted yesterday, you calculate the ID for a new record, but I would like to see where it actually gets put in the table. Thanks.

Pat
Jun 17 '10 #15
AccessBeetle
111 100+
@zepphead80
As soon as you select County from the dropdown it runs the following code to make sure to reach to the maximum number
Expand|Select|Wrap|Line Numbers
  1. ' Loop to make sure you have the maximum number. 
  2.         Do While Not rsCo.EOF 
  3.         rsVal = rsCo.Fields("[ID]").Value 
  4.         ' Change the below numbers of 0 to strip the first couple of 
  5.         ' bits as needed.  Must be the same as your changed above. 
  6.             If Abs(Right(rsVal, Len(rsVal) - 3)) > mx Then 
  7.                 mx = Abs(Right(rsVal, Len(rsVal) - 3)) 
  8.             End If 
  9.             rsCo.MoveNext 
  10.         Loop 
  11.     Else 
  12.         mx = 0 
  13.     End If 
  14.  
Then it runs
Expand|Select|Wrap|Line Numbers
  1. 'Increment the maximum value by one and 
  2.         'combine the text with the maximum number. 
  3.  
  4.     Me![ID] = Me![COUNTY] & "-" & (mx + 1) 
  5.  
  6.     rsCo.Close 
  7.     db.Close 
  8.  
  9.     Set rsCo = Nothing 
  10.     Set db = Nothing 
  11.  
this code and assigns the ID to the record. This is the only code that does ID calculation and assigning.
Thanks
Jun 17 '10 #16
patjones
931 Expert 512MB
@AccessBeetle
But isn't Me![ID] just a text box on your form? Are you working with a bound form?
Jun 17 '10 #17
AccessBeetle
111 100+
@zepphead80
Yes, it is a bound form. It is bound to the table Class. The unique column is ID and surprisingly (but true) it is text.
Jun 17 '10 #18
patjones
931 Expert 512MB
I don't think it is necessarily a problem that it's a text field. As long as you ensure uniqueness of these values, and as long as the field is locked when you are viewing existing records, I think it is okay.

I feel at a loss. I would say that if you want to attach a stripped down version of your database to the thread, I'd be happy to take a look at it.

I will post the attachment guidelines momentarily.

Pat
Jun 17 '10 #19
patjones
931 Expert 512MB
When attaching your work please follow these steps first :

  1. Remove anything not relevant to the problem. This is not necessary in all circumstances but some databases can be very bulky and some things do not effect the actual problem at all.
  2. Likewise, not entirely necessary in all cases, but consider saving your database in a version not later than 2003 as many of our experts don't use Access 2007. Largely they don't want to, but some also don't have access to it.
  3. If the process depends on any linked tables then make local copies in your database to replace the linked tables.
  4. If you've done anything in steps 1 to 3 then make sure that the problem you're experiencing is still evident in the updated version.
  5. Compile the database (From the Visual Basic Editor select Debug / Compile {Project Name}).
  6. Compact the database.
  7. Compress the database into a ZIP file.
  8. When posting, scroll down the page and select Manage Attachments (Pressing on that leads you to a page where you can add or remove your attachments. It also lists the maximum file sizes for each of the allowed file types.) and add this new ZIP file.

When posting, scroll down the page and select Manage Attachments (Pressing on that leads you to a page where you can add or remove your attachments. It also lists the maximum file sizes for each of the allowed file types.) and add this new ZIP file.
Jun 17 '10 #20

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Sarah | last post by:
Hi I have built a database that is currently being used by multiple users. I have not added user-level security to it because I don't understand it very well. I would like to add a audit trail...
4
by: Andy Rigby | last post by:
I'm setting up a small network of 3 WinXp Pro machines and a shared Access database. I need to be able to send faxes from the copy of Access that's running on any of the machines, using VBA. ...
0
by: James Fortune | last post by:
Here is an example of Access creating a single page PDF file. The text in the textbox is scaled to fit horizontally into a grey box 100 pixels wide that is fontsize pixels high. Clicking the...
70
by: lgbjr | last post by:
Hello All, I've been developing a VB.NET app that requires the use of a DB. Up to now, I've been using Access. It's a bit slow, but everything works. I'm at a point now where I need to decide if...
12
by: Mats Lycken | last post by:
Hi, I'm creating a CMS that I would like to be plug-in based with different plugins handling different kinds of content. What I really want is to be able to load/unload plugins on the fly without...
34
by: Mathieu Trentesaux | last post by:
Hello I downloaded Office 2007 for this reason : It seems, once again, that it is impossible to save any modification done in a VBA library, from the main project in Access. The save button...
0
by: nkechifesie | last post by:
I was given a database program in Access to improve. This included enabling an exported table in excel which after update should be able to import back into the previous table. The issue is that the...
5
by: DotNetDanny | last post by:
Hello Machine: Windows Vista Business, standalone machine (no domain). Installed an old classic ASP webapplication in IIS7, running under a new app.pool with 'NETWORK SERVICE' account (using...
1
by: xuki | last post by:
Hi every one! I need your help to solve this problems. I'm trying to creat a wsdl file to a webservice but i'm getting an erros. "Error creating WSDL document:Error creating WSDL: no class...
0
Aimee Bailey
by: Aimee Bailey | last post by:
Hi, i've come accross a problem, and to be honest im not exactly sure how to google keyword the solution, so i thought id post the situation in here. I am building a new usercontrol that relies on...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.