473,399 Members | 3,302 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,399 software developers and data experts.

Assigning autonumber

I am creating a runner table. I need help in assigning a bib number. I could have used runner id as a bib number However, a runner id is assigned to all runners in my database. Hence, it is not unique to a particular race. What I would like to do is input bib number unique to a particular race. I may have 10,000 runners in my database but only 200 runner running a particular race on certain date. Bib Number is a field that is part of race & runner associative table.

One of the ways I tried to assign bib number was able to generate auto-number in SQL query. However, I can not assign or update the auto-number values into bib number. Is there a SQL command I can use in VBA to do that?

Another way was to try to do some kind of record loop. However, this only assigns last value in the loop to all the runners. This is the VBA command I used:

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdAutoBib_Click()
  2.   Dim bibSQL As String
  3.   Dim db As DAO.Database
  4.   Dim querybib As DAO.QueryDef
  5.   Set db = CurrentDb
  6.   Set querybib = db.QueryDefs("qryAutoBib")
  7.   Dim strSQL As String
  8.  
  9.   bibSQL = "SELECT [event-race-runner].*, (select count(*) FROM [event-race-runner] AS temp WHERE eventid = " & Me.txtRaceMenuEventid & " AND raceid = " & Me.txtRaceMenuRaceid & " AND temp.runnerid < [event-race-runner].runnerid )+1 as AutoBibNumber FROM [event-race-runner] WHERE eventid = " & Me.txtRaceMenuEventid & " AND raceid = " & Me.txtRaceMenuRaceid & ";"
  10.   querybib.SQL = bibSQL
  11.   DoCmd.OpenQuery "qryAutoBib"
  12.  
  13.   Dim x As Integer
  14.   Dim y As Integer
  15.   Dim dbase As Database
  16.   Dim rs As Recordset
  17.   x = Me.txtRaceMenuEventid.Value
  18.   y = Me.txtRaceMenuRaceid.Value
  19.  
  20.   Dim var As Integer
  21.   Dim qvar As Integer
  22.   Set dbase = CurrentDb()
  23.   Set rs = db.OpenRecordset("qryAutoBib")
  24.   Dim qSQL
  25.   var = 1
  26.  
  27.  
  28.   Do Until rs.EOF
  29.     qSQL = "Update [event-race-runner] SET [event-race-runner].bibnumber = " & var & " WHERE [event-race-runner].eventid= " & x & " and [event-race-runner].raceid = " & y & ";"
  30.     DoCmd.RunSQL qSQL
  31.     var = var + 1
  32.     rs.MoveNext
  33.   Loop
  34.  
  35.  
  36.   Set querybib = Nothing
  37.   Set db = Nothing
  38. End Sub
  39.  
Apr 11 '10 #1
6 2881
Delerna
1,134 Expert 1GB
Runners have a unique ID and races have a unique ID
Why not combine those two to make your BIB number

eg
RunnerID=1256
RaceID=9456
BibID=12569456

or perhaps
R for runnere and E for Race (Event)
BibID=R1256E9456

or some other scheme of combining them
Apr 12 '10 #2
TheSmileyCoder
2,322 Expert Mod 2GB
Why not create a Primary Key consisting of the 2 Foreign key fields?

And Delarna, I dont see how your first method ensures a unique BibID, since the RunnerID and RaceID could combine to give the same BibID in some cases.

What do you need the BibID for?
Apr 12 '10 #3
NeoPa
32,556 Expert Mod 16PB
As the OP has specified a number of 10,000 runners I expect a 4-digit runner number with a 4-digit Race number would actually resolve to a unique BibID. Clearly all 4 digits of both numbers would have to be used in all cases.
Apr 12 '10 #4
Delerna
1,134 Expert 1GB
TheSmileyOne
If the runnerId is unique and the race ID is unique then the only way to generate the identical number is by using the same runner and the same race ID's....unless individual runnerID's and race ID's are different length numbers which is why I suggested the second (R for runner and E for race).
Which in hindsight I probably should have specified in my post
Also my use of 4 digits was a random choice

It was just a suggestion

Anyway I like your suggestion better
Apr 12 '10 #5
Thank you all for your help. The reason that I don't want to combine runnerid and raceid is because bib number are suppose be a tag number that runner wear on their shirt to identify their runner number. It cannot be a runner ID in my database because a race may only have 200 people while my database has information for more runners. I was thinking about generating a random number for a particular race and thus limiting bib number from say 1 to 250 if I only had 250 runners participating in that race.

Like I showed in my first post, I tried to use two methods but was unsuccessful. Is there a VBA code that I can use to update my bib id field value for each number with a number generated in a query table (this new field simply generates number but is not bound to any particular database table)?

If the above is not possible, can anybody figure out what is wrong in my code. If a particular race has 250 runners, the the code I use will update all runners' bib number with 250 instead of going from 1 to 250.
Apr 13 '10 #6
NeoPa
32,556 Expert Mod 16PB
Assuming runners are assigned bib numbers as they are registered for a particular race, you would need to maintain the last Bib Number so far used for each Race. This would be stored in the Race table. As runners are registered, the Race/Runner associative table would be updated with a new record which would contain the previous Bib value for that race then the Race table would be updated with the new bib number.

May I suggest in future questions you share some name details in your question thread. It makes it unnecessarily complicated to try to help when all we have is a general description of your setup.
Apr 13 '10 #7

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

Similar topics

3
by: Ilan Sebba | last post by:
I have a 'supertype' table with only one field: autonumber. Call this table the 'parent' table. There are two subtypes, 'androids' and 'martians'. Martian have only one thing in common: they give...
2
by: JC | last post by:
Hi, I have a database that imports 4 reports to my "data" table, each report has its own identifier. Then I have a table with Analysts with the report identifier that they are to be assigned to. ...
33
by: Lee C. | last post by:
I'm finding this to be extremely difficult to set up. I understand that Access won't manage the primary key and the cascade updates for a table. Fine. I tried changing the PK type to number and...
35
by: Traci | last post by:
If I have a table with an autonumber primary key and 100 records and I delete the last 50 records, the next record added would have a primary key of 101. Is there any way to have the primary key...
4
by: yf | last post by:
A KB article "http://support.microsoft.com/default.aspx?scid=kb;en-us;209599" tells that the maximum number of records that a table may hold if the PRIMARY key data type is set to AUTONUMBER is...
26
by: jimfortune | last post by:
Sometimes I use Autonumber fields for ID fields. Furthermore, sometimes I use those same fields in orderdetail type tables. So it's important in that case that once an autonumber key value is...
8
by: petebeatty | last post by:
I have created a SQL string the properly inserts a record in the table. However, the insert does not occur at the end of the table. Instead it inserts a record after the last record that I viewed....
11
by: Alan Mailer | last post by:
A project I'm working on is going to use VB6 as a front end. The back end is going to be pre-existing MS Access 2002 database tables which already have records in them *but do not have any...
6
by: ashes | last post by:
Hi, I am creating an ecommerce website using Microsoft Visual Studio, VB.Net and MS Access 2003. I am new to VB.Net When someone wants to register on the website, they fill out a form and the...
7
by: Constantine AI | last post by:
Hi i have a table called preordlin where a csv file imports there data into it. I have an attribute called 'ItemNo' which i need to input sequential numbers for like an AutoNumber but one that resets...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.