Combo box on form

rob.lyles

Registered User.
Local time
Today, 00:21
Joined
Sep 2, 2009
Messages
34
Hi, I would like to add a combo box on my form to add records to my table. Currently I have this box looking up to the field "Customer" on my table. I'm doing this to help the end-user add a new record with a correct and consistent customer name. The problem is that it is showing duplicates. How do I create a combo box on a form that looks up a list of customer names without duplicates and then can add the name I choose to that field in a new record? THANKS!

Rob
 
What is the record source for your "Customer" combo box, is it a customer table that ensures one record per Customer?

If that is the case it should be easy to achieve what you want using the combo box wizard. that will help you look up the customer name, and will store the PK of that as the FK in the table that you want it linked to. :)

Let us know if you need more detail.

Check out this thread, it has an attachment, step by step pics of how to do the combo boxes on a form.
 
It is a customer table that can have many records per customer. It is sales/usage data per customer per month. The combo box wizard is creating duplicates right now, and I tried using it to look up off a query with unique values, but I don't know if I can use that to add new records to the table.
 
Have you checked your table to ensure that there aren't duplicate customer names in there? That is the only thing I can think of.
 
They definitely repeat as new transactions occurr. I just want a list of customers that the end-user can choose from that are unique and can be used to add new records. Is this possible?
 
Yes it's possible, can you post your db, maybe with some dummy info if your current data is sensitive? If you have everything set up correctly is should be working.
 
Rob,
Yes you can do it...but the question I have is why are there duplicates in the Customer table?

Anyways, to have it only list one instance, add the word DISTINCT after SELECT in the row source. Also remember that if the row source has some kind of unique number, you cannot include that in the row source, as the DISTINCT will apply to that field as well.
 
Ok, I'm new here, how would I post my database? Thanks
 
In the post reply, click "go advanced", there will be an option for attachments. (Looks like a paper clip) Make sure you database is zipped. Also if possible, I can only look at 2003 versions as I don't have access 2007.

No problem being new! No worries. :)
 
Ok, I have posted my db. On my form, the Customer1 combo box is in reference to my earlier messages. Thanks.
 

Attachments

OK, You need a separate customers table. Then the main table will reference the customer ID. Check out this revised version and let me know if you have any questions.

EDIT: Also, Your table needed it's own ID and primary key as well. You might want to read up a bit on normalization. There are some excellent threads on this site. One really great one by The_Doc_Man that I'll try to find the link to about how to learn about normalization.

EDIT 2: Here is the thread.
 

Attachments

Looks good, but of course I have questions! I will read up on normalization, thanks for the advice, but in the meantime I would like to know the steps you took and how it works. I see the table tblCustomers, and that makes sense that you have used a Customer ID as a primary key. How does this table tie back to the Main Table and also the form? What have you done to the form so that when I use the combo box it looks up from tblCustomers and updates tbltABLE? I'm not seeing the connection. Thanks for the help so far!
 
Looks good, but of course I have questions! I will read up on normalization, thanks for the advice, but in the meantime I would like to know the steps you took and how it works. I see the table tblCustomers, and that makes sense that you have used a Customer ID as a primary key. How does this table tie back to the Main Table and also the form? What have you done to the form so that when I use the combo box it looks up from tblCustomers and updates tbltABLE? I'm not seeing the connection. Thanks for the help so far!

OK. There was one thing I had forgotten to do, so I attached an updated version to this post.

You are so welcome for the help.

The first thing I did was to create the customer table. With an autonumber as the ID and making that the primary key. The primary key is what you will use to relate the customer table to the main table.

The next thing I did was to add a primary key autonumber ID to the main table. The idea is to create a field that is unique to that specific record in the table.

I then changed your customer name field to a number, and renamed it CustomerID to match the primary key name in the customer table. However, in a table when you refer to a primary key from another table it is called a foreign key. This, of course erased what you had before, but as this is dummy data, it didn't matter so much.

The step I had forgotten, but which is now in this attachment, is to go into the relationships screen and build your relationship between the two tables. In this case Each record in your main table can only have one customer, AND each customer in your customers table can have many records in the main table. This is called a one-to-many relationship. In the relationship screen add your two tables. Then click and drag the customer ID from one table to the customer ID in the other table. A screen will pop up to create the relationship, here it is a good idea to click "enforce referential integrity", I am not quite sure what this does, but is is a good idea to do this nonetheless (I am pretty sure it helps maintain data integrity, just not sure how). Save the relationship layout.

Ok.... On your form, go into design view. right click on the square to the upper left of the form then click properties. Go to the data tab and place your cursor into the record source line. There should then be a box to the right of that line with three dots. click it. There will be a prompt that asks you if you want to build a query, say yes. Here, add all of your fields from the table to the QBE. click the "X" and when prompted to save click yes.

OK, now to add the customer part. Delete the control on the form that has the customer on it. In its place drag a combo box on the form and follow the instructions from that thread where I have already posted pictures of what to do. It's a wizard so it should be pretty easy.

Please let me know if you get stuck in this. It's a lot, I know, and I may not have explained it well. :)

Edit: Oh Yeah, the normalization bit is extremely important. Without knowing and understanding it, you will certainly not be using the database correctly, nor get the most out of what it can accompish for you. So I really do recommend reading up on it.
 

Attachments

Ok.... On your form, go into design view. right click on the square to the upper left of the form then click properties. Go to the data tab and place your cursor into the record source line. There should then be a box to the right of that line with three dots. click it. There will be a prompt that asks you if you want to build a query, say yes. Here, add all of your fields from the table to the QBE. click the "X" and when prompted to save click yes.
Ok, I am definitely understanding now, but I'm not grasping the above. What is the purpose of building this query? Do I have to do this every time I create a form?

One last thing, :), how can I add new customers to tblCustomers from my form?
 
Ok, I am definitely understanding now, but I'm not grasping the above. What is the purpose of building this query? Do I have to do this every time I create a form?

One last thing, :), how can I add new customers to tblCustomers from my form?


It's a good idea to build forms based on a query, but I did it to make sure that the form referenced the changes I made to the table. I'm really not sure if it was absolutely necessary, but it doesn't hurt anything. So you can try not doing this step.

As far as adding a new customer, I suggest making a form for it. Then creating a button on your first form that will open the "Add New customer" form to a new record. Then on your main form in the properties, go to the events, and add code on the "got focus" event that will requery the form so that the new customer appears in your list. You'll probably need help with that too, so don't be afraid to ask.

Also.... Before you make changes, back up your database so that if the changes cause problems you won't ruin your whole db. Back up OFTEN. :p
 
I've begun on my Add New Customer form, and it adds records fine. However I did write over a previous field in a record by mistake. This is definitely something I need the end-user to avoid. I guess here, I need it to start at the first blank record, and I need existing records to be protected from being erased or changed.

And yes, I definitely need help with the code to reqeuery my main form if you don't mind. Please check my current database. Thanks.
 

Attachments

One question- Do you want the main form to open to new only? Or do you want previous ones to be editable. Also, is there a field in the maind table that it would be helpful to "look-up" by on your form? If so what is it?
 
Previous ones should be editable in case of a mistake. The customer name is definitely the best look-up or order number.
 
Previous ones should be editable in case of a mistake. The customer name is definitely the best look-up or order number.

On the same order number, can an order number be on more than one record in the main table?
 

Users who are viewing this thread

Back
Top Bottom