Ms Access Database Pros, a little help to those in the know
DeepRoots
Feb 16 2008, 06:28 PM
Get to da Chopper!
Posts: 2.700
Joined: 18-March 07
From: South Wales, UK
Hey guys this one is for any database know-it-alls

im making a car rental database for my IT project, and in the "Loans" table i have set "Loan number" as the primary key and an autonumber.

What i want is a random number to appear in the table for each loan entry- i have set a random number to appear but i'm interested if i can format this so that only positive values are generated.. and also if i can set a data range for the number .. say 1 -1000.

Thanks for any help- i know there's alot of IT guys out there so im counting on ya wink.gif

You are at GuitarMasterClass.net


Don't miss today's free lick. Plus all our lessons are packed with free content!

Don't miss today's free blues, jazz & country licks. Plus all our lessons are packed with free content!
Go to the top of the page
 
+Quote Post
Pavel
Feb 16 2008, 06:53 PM
Instructor
Posts: 3.764
Joined: 8-January 07
From: Rijeka, Croatia
Isn't it easier to make it an auto-increment value starting from 1? With random generating you may run in a problem of hitting the same number and you'll fail to update the table (this is extremely rare in a range of 1-1000 but it may happen, while with auto-increment it will never happen).

I hope someone will give you the answer you're looking for, but in MySQL database i always do it with auto-increment value.

You are at GuitarMasterClass.net


Don't miss today's free lick. Plus all our lessons are packed with free content!

Don't miss today's free blues, jazz & country licks. Plus all our lessons are packed with free content!


--------------------
"It isn't how many years you have been playing, it's how many hours." -- Prashant Aswani

"PRACTICE, PRACTICE, PRACTICE!" -- Michael Angelo Batio

Check out my video lessons and instructor board!

Go to the top of the page
 
+Quote Post
DeepRoots
Feb 16 2008, 06:57 PM
Get to da Chopper!
Posts: 2.700
Joined: 18-March 07
From: South Wales, UK
QUOTE (Pavel @ Feb 16 2008, 05:53 PM) *
Isn't it easier to make it an auto-increment value starting from 1? With random generating you may run in a problem of hitting the same number and you'll fail to update the table (this is extremely rare in a range of 1-1000 but it may happen, while with auto-increment it will never happen).

I hope someone will give you the answer you're looking for, but in MySQL database i always do it with auto-increment value.


cheers Pavel i'll give it a shot your way if i dont find the answer smile.gif

You are at GuitarMasterClass.net


Don't miss today's free lick. Plus all our lessons are packed with free content!

Don't miss today's free blues, jazz & country licks. Plus all our lessons are packed with free content!
Go to the top of the page
 
+Quote Post
Ivan Milenkovic
Feb 17 2008, 04:34 PM
Instructor
Posts: 25.396
Joined: 20-November 07
From: Belgrade, Serbia
You never set range for primary key man. It doesn't makes sense because when you insert more than 1000 rows in your table (and that will happen sooner than you think believe me), the error will occur. Pavel said it right. You have to set the autonumber value for all your primary keys. Access does this by default anyway so there is no reason complicating. There is no point inserting random number as you primary key anyway.

You are at GuitarMasterClass.net


Don't miss today's free lick. Plus all our lessons are packed with free content!

Don't miss today's free blues, jazz & country licks. Plus all our lessons are packed with free content!


--------------------
- Ivan's Video Chat Lesson Notes HERE
- Check out my GMC Profile and Lessons
- (Please subscribe to my) YouTube Official Channel
- Let's be connected through ! Facebook! :)
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 




RSS Lo-Fi Version Time is now: 19th September 2020 - 05:23 AM