Access form, search for a record from another table and insert into field in current form - ms-access

I have a table that stores invoices and a form based off of that table that looks like an invoice so that you can search previous invoices. Currently I am creating the invoices in excel and then exporting the data as a new record into the Invoice table. I was wondering if there was a way I could create the invoices from my Invoice form. I have a table of all of the products and prices we carry that would used for the invoice.
Is there a way to put a search button on the invoice form that would search for a record or "product" in the product table and insert it into the fields of a new invoice?
I have looked a some code to connect to the products table and insert it into fields in the invoice form, but how do I search as well?
Any thought or ideas? Any help would be much appreciated!!

Handling this through VBA and control events is typically the best choice:
Use an unbound text box in your form as your search input field. This will allow the user to input some text into a box and hit enter, or click some related "GO" button if you choose to perform some sort of search.
Set the `OnChange` property of this text box control to the name of the macro or method you designed to handle this event (or click event property if you've instead set up a button to a) check the textbox value; and b) handle it; typically allowing for both the user pressing enter or clicking the button to perform this action). You may also simply call an `inputbox` from some button click event to pop up a prompt to allow the user to enter the product value to search for.
Within your handling script, use DLookup() to use that user-supplied value against your products table to get some meaningful product value back which you can then place anywhere on your form.
Also, although I'm not familiar with your particular setup, it seems as though you should ditch your excel file and go with a direct user interfacing MS Access input form. You may find it always easier to deal with user input directly rather than indirectly through oustide files. That way, you have better control over user input validation and user feedback vs fearing whatever the Excel client feels like putting in those spreadsheets.

Not sure this is the right design. Do you only invoice one product at a time?
Also, it doesn't sound as if you are thinking in terms of primary keys.
Nor does it sound as if you thinking "relationally".
Let me clarify. In most invoicing systems, there is usually an Invoices table, then an InvoiceItems table. The relationship between the invoice items and the invoice would be one invoice to (potentially but not necessarily) many items.
Then you have your Products table. The relationship between the Products and InvoiceItems is one product to many InvoiceItems. Ie, you can sell a given product to many different customers.
So we have:
Invoices --> InvoiceItems
Products --> InvoiceItems
Now you need to implement this in your forms.
Matching your tables and their relationships, you create an InvoiceForm and you create an InvoiceItemsSubForm. The InvoiceItemsSubForm, to hold many items, is a continuous form.
In the InvoiceItemsSubForm, you will have a field that takes the Primary Key of the Product (along with other fields such as date, number of products purchased, etc).
To search for your products, you can have a combo box that has the ProductId and ProductName fields. This combo box serves two purposes: it allows you to search for your products, and it allows you to input the product you want in your InvoiceItem record.
If I have misunderstood your question, my apologies. If I haven't misunderstood your question, you have a lot to learn...

Related

Saving Master Table from Form built off Multiple Tables Microsoft Access

I am new to Microsoft Access and I am trying to build a Case Tracking system for our Employee Relations folks. I have a table for Employees and a table for Cases. They are linked by Employee ID. I also have a form to incorporates fields from both tables so they can fill out when a case comes in. How do I save the data on the form into a master case history table? I want to capture the employee data as it was when the case was added since departments, managers and other fields are dynamic for the Employee. My form includes:
Employee Table
Employee ID,
Company,
Job Family Group,
Cases Table
Case Number,
Case Date,
Case Type,
I know I can obviously write a query to join them, but it will show me the employee facts as they are as of the last data refresh. Any help you can provide would be greatly appreciated! Thank you again.
Actually, the way you approach this?
Well, you have a main form - employees.
Then, you have (make) a sub form of cases.
Now, that sub form can be a grid like display - perhaps you select (click) on a row to show + edit more details, or perhaps just a sub form as a grid (continues form) will suffice.
In other words, you don't make the form update both tables at once, but in fact use a main form, and a sub form.
Say, I have a table of Hotels. And I need/want to display hotel information, and THEN ALSO display people booked into that hotel?
so, I create a form based on table People. That table People of course has a column that relates back to the hotel they are booked to.
So, you get this:
So, each form STILL ALMOST ALWAYS will be based on ONE table. Don't try and make some multi-table join for the forms data source.
So, in your example?
you build a main form - employees - it can show all the information (and let you edit/add etc.) to that form.
For each case, from the case table?
Well, go off and build a 100% separate form for display of "case(s)".
Then save that form. Now, open up your employee form, and in design mode, simple drag + drop in the cases form into that form.
So, you don't actually base the form and its table on more then one table, but you combine multiple forms EACH based on their one respective table.
But, as above shows, the end result is a main form + sub form, and that gets you the relational database setup, and allows you to do this without having to write code.

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.

Checkbox per row in multi user access database

I have the following situation:
I have a many to many relationship.
For example an Employee Table, an Course table, and an relation-table inbetween.
Now I want that the user can select out of the course table his courses in a dialog form.
That means that the underlying table for my continous form inside the dialog is the course table.
I want a checkbox in every row which indicates if the course is selected or not.
As I read it is not possible, to add an unbound checkbox, because they are just copies, and a select click would select all of them.
The solution would be to add an yes/no field to the underlying table courses.
But here I have the problem as I understand the matter, because I have several users using the database at the same time, that the underlying table will be updated if I click one checkbox and this update will select the value for all users which are using the dialog form concurrently, what I dont want.
So my question is, is there another solution to get a working checkbox per row in a multi user access database.
There are two solutions which I could imagine:
1) The underlying table will be the relation table and in this every possible combination between employee and course will be saved together with a yes/no field. (but that would be from a data view point quite horrible)
2) If the changes to a checkbox would not be directly written back to the database table, I could discard them on saving and manually insert the relation records in the relation table. (Is that possible?)
Thanks for any solution proposals
I see two good approaches:
1) This assumes that your database is split in a network backend + each user has a local frontend. This is the recommended setup for multi-user.
The frontend has a local table with Course_ID and a yes/no column.
A join of this local table with the Course table is the recordsource for your continuous form.
On loading, you copy the course ids into the local table, and set the existing relations to True.
On saving, you update the relation table.
2) Use a ListView control instead of a continuous form. It has inbuilt checkboxes. Loading and saving is done with a VBA loop.
Based on your description I assume your form has a LEFT/RIGHT JOIN in its data source where some ID field is null if the specific Course/Employee combination does not exists in your relation table. Let's call it LinkID. Then your checkbox should be something like =NOT ISNULL(LinkID). While you will not be able to use the OnClick event for the user to check/uncheck this way, you can use the onMouseDown event to see if the user clicked the checkbox and take action accordingly.
That way you don't need an "all combinations" relations table, no temporary table and no Yes/No field. If a record with the Course/Employee combination exists the box is checked, if it does not exists, it is not checked. Adding and removing courses is done by adding and deleting records from the relation table.
Have a look at this How to use unbound checkbox in a Continuous Subform - MS Access. A class that binds an unbound checkbox. Better than listbox, because you have a form with all its benefits (sort, filter, edit, append).

Suggestion and auto-complete in form with one-to-many relationship in Access

I am trying to make a form for a very typical scenario: a customer makes an order. The customer might be new or returning. I have created an Access database with two tables: Job and Customer (linked by the primary key 'customer no'). The form I wish to create looks like this:
The customer table data is highlighted.
When the customer's name is beginning to be typed in, I want to see an updating list suggesting possible customer matches. If the customer happens to be returning, I can click on one of the drop-down options and have all other customer fields auto-complete.
What is the best way to create such a form?
I tried to achieve this using a comboBox and some code. However, if I use this method, the comboBox does not allow me to enter a customer name which isn't already in the customer's table. So I can't enter new customer details.
Ideally, this auto-complete/suggestion should work for all customer fields, such as phone number (in case the phone number is the only know customer info).
You could use a combobox which has LimitToList set to false, allowing entry of data not already defined in the combobox's rowsource; With this approach you would define a not-in-list event handler for the combobox to open a popup form for adding a new customer, ideally pre-initialised with the customer name just entered, and when data is saved in that form, control returns to this form, requeries the combobox (as it's contained data is now out of date), re-locks the customer just added, and fires it's after update event to display all the relevant customer-related fields appearing on this form.
However whether this is appropriate or not depends to some extent on the quantity of data that you have. If you've more than say 10000 customers in the database, I'd recommend instead having an elipsis (...) button beside customer name which opens a popup search screen, and provides whatever search options seem best (name, number, city, etc) for the entity being searched, a textbox, and find + add buttons; With huge data quantities you might also want to provide a means to prevent searching for matches (especially by multiple users across a busy network) where there is less than say 4 characters in the textbox, to improve performance.
You'd then use the text_changed event on the textbox to retrieve the data in the database which starts with the text currently existing in the textbox, and display this in a datasheet; The user can then either click Find or double-click the datasheet to select a customer which you then return to the calling form, probably by either a call to a public sub, or setting a tag value on that form - or click Add to add a new customer and invoke logic similar to the above.

Many-To-Many MS Access Form With Checkboxes for All Options

I'm working on a Microsoft Access application for a summer camp to track which entities have signed up for which activities. There is a form for editing an entity's information. I would like to add to that form a list of all activity options. By each option should be a checkbox. When the checkbox by an option is checked, a entry should exist in the many-to-many junction table linking the entity with the activity.
Google offered some examples of building many-to-many forms but none (at least that I found) showing how to provide a full list of options with checkboxes.
How would I do this?
Database Table Layout:
Entity (EntityID, first name, last name, etc.)
Activity (ActivityID, activity name)
Entity_Activity (EntityID, ActivityID)
One way to do this:
Create a new entry in the Activity
table.
Manually insert one checkbox
per activity on the form.
Register
an onClick handler on each checkbox
that adds the appropriate row to the
junction table when tje checkbox is
checked and removes the appropriate
row when the checkbox is deselected.
I was hoping for an approach that didn't require manually laying out the form. With this method, every time a new activity is added, the form must be modified. Oh well....
Instead of check-boxes, the more natural way to do it with MS Access would be to have a list of activities (in a sub form) that each entity is signed up for. Activities would get added from a pull down list (and perhaps an Add button), and removed with a Remove button. With a clever query, you limit that list to only activities that the entity doesn't have yet.
Alternately, you could go with the checkboxes, but you'll have to modify your table layout slightly. Entity_Activity would need a third field (SignedUp, yes/no). You would then have to populate every Entity_Activity combination when you created a new Entity. However, if you should happen to add another Activity later on, you'll have to go through some hoops to get all the existing Entity's entries updated.