Car sales database - is this possible...

l_jonson

New member
Local time
Today, 12:20
Joined
Dec 16, 2004
Messages
8
Hi all,
Looking for an expery to help me out please!

I will try and simplify my problem below:
I have a used car database.
Tables include:
Cars in stock P.Key=Registration Number
Cars sold P.Key=Sales ID
Invoice P. Key=Invoice ID
Warranty P.Key=Warranty ID
Customers P.Key=Customer ID

1. When a car is bought, a form is used for inputting details.
2. When car sold, form used to a) enter registration number of car
b) show details of car
c) calculate final cost depending on warranty
d) fill in customer details
e) print invoice

3. When car is searched for, use a form to specify search criteria and find matching cars that appear on the form.
4. Need a form to view any past searches made
5. Need to be able to view cars sold - in a form

I would be grateful if someone can let me know if all this can be done in a database. i have managed bits, but things like 2. i don't have a clue!

Also, if anyone can let me know how best to arrange the relationships, i would be extremely grateful.

Thanking you. :)
l_jonson
 
OK, here's the straight skivvy: We can't tell you without knowing your business rules. But I can tell you how to figure this out for yourself.

1. Read up on the topics of NORMALIZATION so you don't commit too many tabular abominations. (It's an easy, common, and pesky mistake that lots of folks make when getting started.)

2. Get a dry-erase board and a box of sticky-note pads. You might already have the board. Sticky-note pads are cheap and you can use the leftovers in your office.

3. On your board, write table names. Using sticky-notes, write some entries that will become individual records in each table. Populate your tables.

4. Draw lines between tables that are related to each other, naming the nature of the relationship. I.e. you mentioned yourself that you would have an Invoice table and a Customers table. There's a candidate for a relation right there.

5. Perform (by hand) a few operations of each type you anticipate. Remember the "old programmer's rule" - if you can't do it on paper, you can't do it in Access. Think about not only the immediate task - storing the data, but also the later tasks - creating reports you want.

Now, as to your tables...

Customer table: Good Idea

Stock table: Good Idea

Warranty table: Probably a good idea if you have only a few possible warranty contracts to select. If every sale has a slightly different warranty, this should be in the Invoice table or the Cars Sold table.

Invoice: Good Idea needing exploration.

An invoice should contain a customer ID and a Stock ID, plus date and other things about the sale. If my guess is right about warranty, you would also enter the warranty-type code number here. But just for shoots and giggles, what if someone buys more than one car? Does your business rule require you to write two invoices? If NO, then this table needs to be divided in two parts - one-to-many relationship, where the customer ID is in the master invoice part and the car being sold is in the invoice detail part.

Cars Sold table: EITHER this is redundant data OR you just named the "many" side of the situation for which INVOICE is the "one" side of the same thing. (In which case there is a relationship between cars sold and the invoice number under which that sale was recorded.)

Now, as to some of your questions:

I would be grateful if someone can let me know if all this can be done in a database. i have managed bits

Yes, it can, for the most part. But some of what you want might not be trivial. My best advice is to pick some element and focus on that. Use old Julius Caesar's methods - Divide and Conquer! Works every time. (Also is part of the Edward Yourdon Top-Down-Program-Design method, which is highly respected.)

Now, I'll probably shock some of my colleagues here, but... your BEST BET is to start with the Form Wizard to build your forms. As you gain experience and courage, you will sneak in using Design mode and customize the heck out of everything. I still do it that way today 'cause the wizard can build a basic form faster than I can. But I can make it prettier. And once I've got the framework, I can make it jump through my own hoops.

Also, if anyone can let me know how best to arrange the relationships, i would be extremely grateful.

Once you have identified the data you will be keeping, examine each table. Where you have something that is guaranteed unique, you can use it as the primary key. For instance, VIN on a car should be unique. But if you don't want to use that, then for every table, include an autonumber field (that's one word, not to be confused with auto number 'cause you're in auto sales.)

Autonumber fields CANNOT be assigned any meaning other than as a unique number that won't ever be duplicated in that table. You CAN use the autonumber as an INVOICE number but be aware that if you ever cancel an invoice, the number sequence doesn't reset to re-use the number you STARTED to use. I.e. gaps will appear in autonumbers that allow you to back out of saving a record. So you CANNOT base business decisions on the consecutive values of an autonumber field. You can only base RELATIONSHIPS on such fields.

Now, how do you arrange them? In the tables where the item is defined fully, the autonumber field becomes the Prime Key for that table. In any other table, all you need is a LONG field to hold that same number as the FOREIGN key. For instance, the Cars Sold table would not repeat data for the car if it is already in the stock table. All you would do is store the Prime Key of the selected Stock table in the Cars Sold table as a pointer that says, in effect, "That's the car I just sold."

3. When car is searched for, use a form to specify search criteria and find matching cars that appear on the form.

Not trivial. Look up the topic "Cascading Combo Boxes" in this forum for some lengthy discussion on how to do this sort of thing. (I'm assuming you will do searchs on multiple fields at once.)

4. Need a form to view any past searches made

This is tricky and requires reference to another aphorism: You can't recall what you don't remember. To remember a search, you must store the data of the search. I would perhaps want to shy away from this one. Access is likely to be fast enough to just REPEAT the search

5. Need to be able to view cars sold - in a form

Or a report, makes no difference. Your "Cars Sold" table - regardless of its parent or child status - is how you would approach the problem. This table tells you the stock ID of every car sold. So you would base a report off this table or a query of this table.

You would need lots of tables JOINed through queries. For instance, an Invoice joins to the Cars Sold table through invoice number. A car sold joins to the Stock table through Stock number. An invoice joins to a customer through a customer number. So read up on JOIN issues (including the queries section of this forum.)
 
Go with the Doc Man.

However, I would point out that if you are in the UK, using the registration number as a PK is a bad idea. Registrations can be transferred and if you have a customer that trades in a car with a personalised registration and wants it transferred to their new car, you'll have two cars with the same registration. Use an autonumber as a PK instead. Strictly speaking you should allow for vehicles having more than one registration number by having a table for reg nos linked to the vehicle PK.
 
All good stuff so far.

Just a comment on Cars in Stock and Cars Sold tables

Maybe I missed something but think maybe this is one table.

Only difference in the vehicle is its Status. For sale or Sold. Could be indicated by presence of an Invoice.

This way all car searches relate to one table only

Len B
 
Wow! Thanks for all the replies. Looks like i'll be busy!

Ok, so I have created the tables and normalised them as best as I can. I agree, there is not much point in the Cars sold table as the data can be in the cars in stock table.
Just a few questions pls:
1. Will i have to use update queries?
2. I have created a cascading combo box for my "Make" And "Model" fields. These work fine, however, when a basic query is performed to find all "fords", it produces a number. This number relates to where "ford" would be in the separate table needed for cascading combos to work. Any way of getting round this?
3. Last one - can u have a form where you can enter details of the car, e.g "ford" , and it finds it and presents it in a form layout?

I would again appreciate a reply - Thanks very much for ur help .
l_jonson
 
for the combo box issue, look at the data tab in the properties for the combo. the rowsource should include 2 columns: the primary key number (sounds like that's displaying fine) and the 'make' column from the same table... and the 'bound column' should be 1 if the number is the first field in the rowsource query, and 2 if it's the second.

then on the format tab, the number of columns should be 2. then you set the column widths separated by semicolons... so if the number is first, and the make is second, the widths should be 0";1". this way the first column (numbers) is 0" wide (hidden) and the make column is 1" wide (shown).

so.. the result is a combo box that displays the make, but is bound to the primary key of the table, even though it doesn't show up. make sense?
 
l_jonson said:
2. I have created a cascading combo box for my "Make" And "Model" fields. These work fine, however, when a basic query is performed to find all "fords", it produces a number. This number relates to where "ford" would be in the separate table needed for cascading combos to work. Any way of getting round this?

You haven't set the number of ColumnCount and ColumnWidths properties of the combobox.
 
Just a simple observation. I wouldn't call the table "cars in stock" as they won't be. Some hopefully will be sold ;) Call it "Cars" - or if several words, don't have spaces in table names ie - "CarDetails"

Col
 
After thinking about it more, I'm not sure I agree with the folks who said the "Cars Sold" table is redundant. If Cars Sold is the many side related to a single invoice in the Invoice table, it is NOT redundant.

I'm not familiar with your location's car-buying habits, so I'm only guessing that this might happen. If anyone buys a car from you and later sells it back and then you sell the same car again to someone else, having the entry in "Cars Sold" (as a detail of an invoice) is no problem.

BUT if it was subsumed into the Stock table (i.e. you have an Invoice number in the Stock table to show when it was sold) and you DON'T have an invoice detail entry (regardless of what you call it), you just lost historical data when you made the second sale. If all that happened in the same tax year, you would have problems correctly computing sales income.

From a normalization standpoint, guys, those of you who suggested that Cars Sold is superfluous, think about this:

The sale includes a date and invoice number. The Stock table does not relate to a sales invoice. Making the stock table entry point to an invoice violates a normalization rule. Remember, entries must fully and completely depend on the primary key of the table, not just part of it.

Stock exists on its own. An invoice exists on its own. A Car Sold has to (a) be in stock and (b) have an associated invoice. I.e. TWO required keys. Which is why you would have a linking table or line-item table.

FURTHER, in the "same car sold twice" case, now the DATE of the sale becomes an issue because the date identifies the sale. BUT given that the invoice also implies a unique date, storing references to the same car twice (as two different records that are children of two different invoices) is not a violation. Making the Stock table entry point to the Invoice a second time IS a violation.

3. Last one - can u have a form where you can enter details of the car, e.g "ford" , and it finds it and presents it in a form layout?

Yes. Again, start with the wizard. One of the options in a combo or list box is not to store data but to find data. Make one of those boxes on a dummy form. Look at the code it generated. Using the cascading combo box concepts, you can build off that code to customize searches that find various elements in your Stock table.
 
Doc Man - Top Man!

Hi Doc Man, I really appreciate all ur help. I was wondering whether it would be possible for me to send u my dbase, and if u could let me know what u think so far. I would grately appreciate it - however, would understand if you don't have the time.

thank you once again :)
l_jonson
 
Time's not as much an issue. My site has strict security rules about downloads. I cannot download from the forum or commercial sites. I'm on a military sub-net of the Internet. I have to limit my traffic, too. So I'm afraid all I can do is try to offer relatively quick answers and suggestions.
 
Doc_Man may well have a point regarding the CarSold table.
However when a car is sold an invoice reference in the car table is the foreign key relating to the Invoice table.

Now if a car is subsequestly repurchased and becomes "In Stock" again then that's okay because the primary key will not be the Registration Number but some other unique identifier. Therefore it can be sold again against a different Invoice number

Now I am not saying anybody is right(me) or wrong (Doc_Man). You need to model your application fully and the normalise

My thought is that since only the invoice reference (foreign) key is necessarily present in the Car table then normalisation rules are okay.

If the car is sold a second time then it will have a different invoice reference. All sale dates are within the Invoice table.

Interesting as ever to discuss Normalisation issues

Len B
 
Len - I guess the point is whether selling the same vehicle twice (which means you also BOUGHT it twice) results in ONE or TWO entries in the Stock table. If TWO entries then perhaps it doesn't matter. And of course, we mustn't forget that for a small enough business, the occasional duplicate record (same data except a different autonumber) won't kill anyone. BUT it still could confuse the issue when searching, depending on how the search was done.

Now, if the car is bought a second time and DOESN'T result in a second entry in the Stock table then another table is required to record the second purchase of the car to bring it into stock. In other words, the incoming Purchase-Order equivalent of the Invoice that represents an outgoing car.

If you are going to do it with an Invoice Detail table, you must do it symmetrically with regard to obtaining the vehicle, I would think. So if you don't have a Cars Sold table as a detail, it might not matter whether you make extra records anyway.
 
Doc_Man

I think you have exactly hit the point.

If one of the attributes is bought in price then there will be two entries in the stock table.

Depends what is defined in the Enterprise Rules

Len B
 
Thanks for all the replies. I have re-instated the CarsSold table.

A few more questions pls:
1.
For the invoice table would it be adequate to have simply the primary keys from all the other tables, eg. Cust ID, Car ID etc. etc. Could I add other fields present in other tables, eg. customer address, date sold, or would that be duplicating data?

2. When i made the cascading combo boxes for the "Make" and "Model" fields, I had to create 2 separate tables, namely "Make" and "Model", containing the info required for the combo boxes to work. I linked these, but on the relationship diagram - they look a bit isolated - is that OK?

3. Would I need to have primary keys from other tables in all my tables? so they would be acting as foreign keys? eg. in warranty table, have carID, cust ID etc.?

thanks once again - l_jonson :)
 
Could I add other fields present in other tables, eg. customer address, date sold, or would that be duplicating data?

Probably would be. Use joins or lookups to find things in other tables if you have a link to those other tables - like the PK of said table.

When i made the cascading combo boxes for the "Make" and "Model" fields, I had to create 2 separate tables, namely "Make" and "Model", containing the info required for the combo boxes to work. I linked these, but on the relationship diagram - they look a bit isolated - is that OK?

This is a side-effect of the business rule that lets you search for make and model separately. I.e. you can search for Fords, or you can search for Anglias, or ... There are ways to recombine them but lookup boxes want the lookup field to be the prime key and you can't have two prime keys in the same table. So, like I said, a side-effect.

Would I need to have primary keys from other tables in all my tables? so they would be acting as foreign keys? eg. in warranty table, have carID, cust ID etc.?

Only where the references make sense. I.e. your "Cars Sold" table would not have to have a reference to your customer because that reference is in the Invoice table (the parent of the Cars Sold table.) Here, the customer is still knowable through joins or lookups, but in general a line-item table that is part of a single invoice doesn't need to duplicate the data of the invoice. Only the invoice number. By contrast, the cost of the car belongs in the Cars Sold table 'cause that detail applies to the individual sale. The invoice only needs the price summary, and that can be done via query.
 
Thanks Doc-Man. I greatly appreciate all ur help.
It is all making sense now (i think). one final question please:

i have set up the relationships as follows (ignoring the carsSold table for now):

tblCar (p.key=CarID) = 1 to Many =CarID in tblInvoice(p.key=InvoiceNo.)

tblInvoice(p.key=InvoiceNo.) (f.key=CustomerID)= 1 to Many = CustomerID in tblCustomer(p.key=CustomerID)

tblInvoice(p.key=InvoiceNo.) (f. key=WarrantyID)= 1 to Many= Warranty ID in tblWarranty(p.key=WarrantyID)

i hope it makes sense - if so - are there any blatent errors? this hopefully will be my last question - so u guys can have a deserved break!

:) thanks
 
talk about digging up the past!! anyway, i'm in the very early stages of attempting the same project as described here. just wondering if you ever completed your project ?
 

Users who are viewing this thread

Back
Top Bottom