Restrict Entry of Duplicate Value in Access Table - ms-access

I am new to Access VBA.
I am making a simple form which will insert data into the table. The table is as follows.
The form has two textboxes and one save button.
textbox1 = Category Name
textbox2 = Item Name
What i want is when the user press the save button, the code should check the duplicate entry comparing both Category and Item Name.
For Example, if the user enters Fruit in Category Textbox and Apple in ItemName textbox, then system should prompt for duplicate entry. However, if the user enters Vegetable in Category Textbox and Apple in ItemName textbox, then system should allow to make entry in table.
Kindly help.
Regards/

I assume you want this behavior regardless of the way you enter data. Then you should create a unique index on those two columns. Check eg. this.

Related

How to get combo box selection to fill related fields with data

I have a table [inventory] with inventory items, and a bunch of columns with different information for those. Mainly, part#, description, price. I am trying to create both a purchase order form [POForm] and, and a inventory transactions form [TransactionsForm], but that one thing I've been stuck on is getting a combo box look up I use to select the part# from [inventory], to also fill my fields for description, and price for that item in my form. I need the fields that are filled to be able to have formula's run off of them, and the information to be saved into the table for that form [TransactionsTable], [POTable].
I've tried making my part# combo box include the fields for the description and price, and using =[part#].[column](x) in the other fields as a lookup, and it looks right visually, but that is apparently just a visual of that data, but technically the field is still blank, because those other fields remain empty in the table for that form, and I am not able to run a formula off the price.
As per my understanding and please correct me if I am wrong. you have a form that shows your inventory data Part# Description & price. This form has a combo box that allows you to select a particular part # to view its related record data description and price.
Now you want to click a command button after selecting a particular part # to update your transaction form and POtable.
1.you have to create a query,
2.insert the inventory table in it
3.select append from the query type in the ms access ribbon
4.a window will appear, choose the transaction table as the destination table to append to.
5.double click on the fields that you want to retrieve its data from the inventory table
6.then in the table below in the query itself in the "append to" row you will find drop-down menu including all the fields from the transaction table. choose the corresponding fields. note if the fields have the same name in both tables access will do it automatically.
7.in the criteria row type the following [Forms]![Inventory Form Name]![the name of the field in the form]. do that for each field in the happen query.
8.save the query and name it
9.go-to design view in your inventory form and create a command button, in the click on event creat macro of the following: openquery-->type the append query name
10.save and close macro builder
11.open your form, select part#, click on the button
12.access will ask you to confirm appending process. click ok/yes
13.check your transaction table to confirm that the append process was successfully performed
14.Tip if you do not want the confirmation msg of append to appear, in the click on event go to the macro builder and choose in the ribbon show all actions then in the first line of the macro builder insert setwarnings - NO
the same is to be applied for the POtable.
Anyways, I hope you find this clear and helpful but I have only one concern you do not have to append part description and price in transaction and PO tables as you already have this data in your database in the inventory table. Generally speaking no need to include the same information in multiple tables otherwise you are not benefitting from the idea of a relational database.
I hope I addressed your inquiry.

MS-Access: Entering data via a query, how can I auto populate a column?

I'm entering data by using a query on a subform. I want to auto populate a job number to each new line I add to that subform.
tbl_Jobs
[Job_ID] <Primary Key
JID1001
JID1002
JID1003
tbl_Job_Tasks
[ID Auto][Job_ID][Task]
1 JID1002 TASK1
2 JID1002 TASK2
3 JID1002 TASK3
4 JID1001 TASK1
Here's my query at the most basic level...
SELECT tbl_Job_Tasks.[Job_ID], tbl_Job_Tasks.[Category], tbl_Job_Tasks.[Task]
FROM tbl_Job_Tasks
WHERE (([Job_ID]="JID1002"));
What I want to be able to do is hide the Job_ID column and have it auto populate for the user if they decide to enter a new task for their Job. Currently if I enter a new task I have to specify the Job_ID to use. This query is being used on a sub form that pulls its Job_ID from the parent form, so in a perfect world the end user would not have to re-enter the Job_ID.
Is this possible?
Thank you,
If the subform is linked to the parent form correctly (Using the Link Master/Child Fields property) the child records foreign key (in your case tbl_Job_Tasks.Job_ID) should be filled out automatically.
You shouldn't even need the query unless you are filtering the sub forms records in some odd way.
Edit - Have a look here http://www.access-diva.com/f2.html for a solution to your unbound problem.
Just to sum up the solution.
Link the Master and Child Fields to the sub form.
If you're getting a "Can't build a link between unbound forms" error, you can go into design view and manually type in the Parent/Child fields.
After that, the field will update automatically when entering a new row.

Access 2010 - display related record in a form

I have 2 related tables.
Invoice (fields: number, buyer, supplier, etc.)
Company - all buyers and suppliers (fields: name,etc.)
Buyer ans supplier fields on invoice are referencing same field (company_id from company table)
On invoice form, I choose supplier ID from dropdown list and also buyer ID from dropdown list.
Task: To make the form little bit readable, I would like to automatically display a name of company after selecting company id in both fields.
What I did:
I manually dragged the company name field to the form and wizard asked me which field I would like it to connect to (byuer or supplier), so I got 1 field working. How to create another field that shows company name? If I drag another instance of company name, wizard does not show so I can set it up and I can not find anywhere setting for that. Thank you for help.
I think the best way is the following:
Create a lookup query: Create a new query similar to this “SELECT CompanyId, CompanyName FROM t_Companies ORDER BY CompanyName;” and save it as “ql_Companies”
Edit your Invoice table. For both your fields Buyer and Supplier do the following: Click on the field and select Lookup in the filed properties. Set the following properties: Change Display Control = Combo Box, Row Source = ql_Companies, Column Count = 2, Column Width = 0;5 and save the table.
Now when you create a new form based on your Invoice table the field will be automatically shown as a combobox.
You can also do all this manually on an existing form but then the combo box will only show on this one form. If you prepare the underlying table with lookup queries then this will work in all queries and forms automatically without additional work.

Microsoft Access 2007 Input Form

i am new in MS Access database and i have a problem to in insert form. I have already
created a relational database in MS Access 2007. Now i need to create forms to create a insert data.
Let me go with details,
I have two tables,
User - Columns(Id[PK],Name,Address, CountryID[foreign key ])
and
Country - Columns(CountryID[PK],Country Name)
So i need to create a input form for User table that will display the Country Names as Dropdown/select box and the data will be showed from Country table. When anyone selects a country i will save the CountryID of that country.
I have checked in googled but almost all of them stores the same value that is selected but i don't want that. In my case if a Country Name is selected then corresponding CountryID will be saved.
Thanks in advance.
pks
Right-click on your dropdown box. Select the Properties menu.
Scroll down to Row Source Type. On the right side you should see a
drop-down arrow. Click it and select "Table/Query"
Just above that you should see Row Source. All the way to the right
you should see an elipsis ("..."). Click that and select your Country
table.
Just below that you should see "Bound Column". Make sure that's set
to "1". That will bind the first column to the "Value" property.
Now, when you select a country from the dropdown, it will display the name but will have a value of the ID. So, Country.Text will be the name, Country.Value will be the ID.
Go to design view of the form. you use the Control Wizard when you add a combobox to your form, a wizard will guide you through the steps of storing the ID, but showing the Name. Go to the Design tab. Click on the Combobox icon and then click on your form. If a wizard does not start, go back and turn on Use Control Wizards on the dropdown list under the icons. On the first screen, choose I want the combo box to get the values from another table or query. Then you'll specify Table: Country. Add CountryID and CountryName. Sort by CountryName. The next screen will hide the CountryID (because it is a primary key) and just show the CountryName. Specify that you want the value to be stored in the User table's CountryID field. Specify a label and click finish.

Passing information from form to form in MS Access

My setup. I have a form that searches through a table names Students containing student information, ID, Name, Home Room, etc. The form text boxes are parameters in a search Query, which then puts its information into a Multiple Items subform.
My goal is to add a button beside each student record on that subform that will do two simultaneous things:
1) Add the student ID to an Incident Occurences table.
2) Open a form to the record just added and edit the values in other fields for that record.
For example, if John Doe decides to draw on his desk, a teacher will be able to search for John Doe, click a button. His student ID goes to the Incident Occurences table, and a form opens up where the teacher can edit the fields for the new record, to add information like what happened, time, etc.
I know how to open a form to a specific record, using the form filter. I also know how to add the student ID to the form. What I don't know is how to get the ID of the record added with an Append Query.
Thanks.
I would do it in VBA. Run the Append query via code, and then open that table and do a MoveLast. You can grab the ID of the last record that matches your student. You can't get the ID of a record until the record is written, so I think that's the only way to do it.