I have an Access table "Contacts" that looks like this:
Contact Extension
Bill Mann 7283
Jim Bob 2563
Sue Zan 5963
etc...
I have another table "Departments" that looks like this:
Department Description
0040 Fun station
0110 Happy town
0110C Happy town with clowns
etc...
I have created a form that pulls in data from Contacts as well as Departments to make some assignments:
What I would like to do is automatically populate this form upon opening, with the latest assignments that were made by the form. Then these assignments can be changed and saved at will. To me this seems to mean that the combobox will be assigned a default value from a table that is distinct from the Contacts and Departments tables. The problem I am running into is that I can't seem to find a way to assign those default values and allow all of the possible choices from Contacts and Departments.
I am happy to use a VBA solution if necessary.
It seems you need a third table to save the "Packaging Materials Assignments" and that the form should be bound to that table.
Then you set each of the fields on the form from each of the comboBoxes. Then save the record and your current assignments are saved.
When you open the form, you see the way the assignments were most recently set. Then you can change the assignments if needed.
I might be convenient if you set the form's Property.Cycle = "Current Record". That way there will only ever be one record in the third table. Also after creating your one record, set "Allow Additions" and "Allow Deletions" to be false for the form.
Related
I am trying to build a simple ms Access database.
For the sake of convenience, I will translate into sales, orders and such.
Orders
OrderID - PK (auto number)
Client ID - FK to clientID in the Clients table
Clients
ClientID - PK (auto number)
LastName
FirstName
Company
Address
...
I created a form (main form) that allow the user to specify details for a new order, including the client details.
The same form is used to look the details of older orders, to change their step for instance.
When the clerks types in, I don't know if the client is already registered. After everything has been completed, the clerk saves the new order as a new record in the Orders table.
However, Access complains rightly that the clientID FK has not been set: we set the clients name, first name... but not the ID.
My ultimate goal is that, at the saving of the new record, a request that look up into the Clients table to identify a list of possible candidates that match the client first and last name and open a form (contact form) that nicely displays the data from the first record of the request and allow the clerk to navigate between the records, and eventually select one or select create new record with the data from the main form.
I figured that a good place to do this would be in the save button on my form.
I tried to add something in the event code (macro) with something like (not VBA, a pseudo code I've never seen in the other office applications):
if IsNull([main form]![clientID]) then
bip
launch a request to identify the clients in the clients table with the same first and last name
open a form to look into each selected record and select the correct one or if none is identical generate a new one and return the clientID
end if
executeMenuCommand
command saveRecord
The code I tried above didn't even bipped...
I have placed the bip first, and that didn't bipped either.
I receive a message (explicit) that ms Access could not find a record in the client table with the specified clientID.
So I guess my main question is how do I test if there is a clientID associated with the current record?
The next problem is to come back to the main form with the selected clientID.
From what I have seen in the templates provided by Microsoft, it is avoided by defining a single field for customer in their main form. This field is a list populated from the client table, and if you stray away from the list you get a new form for editing a new client.
This is not the behaviour I am looking into. I need to have the posibility to free text enter every field and chose at the saving moment to create or not a new customer.
I hope I am clear enough, please feel free to ask for more details.
edit: thanks to Gustav's hint, I figured that the event was not to be associated with a button click but on the form itself. It helped me uncover other underlying problems... so I guess my problem is not ripe anymore for soliciting external help.
In VBA, use IsNull, and Me if the form is bound to table Orders:
If IsNull(Me![clientID].Value) Then
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.
I have a form that uses a query to open and display a specific customer info based on a customer ID that is manually entered by the user.
The form populates with the customer info from a table where the customer ID can only occur one time. A sub form opens below the customer info with a list of items owned by that customer from another table where the customer ID can occur many times but the items owned is limited by a unique Serial Number.
I have this form set to No Edits so someone does not hose up the original data.
I would like for the user to select a particular Owned Item / Serial Number, and have that SN copied and used to automatically populate another query to open a new work request on that SN.
I don't know if this is possible or not but if so some help with the code or macro would be most helpful.
I understand that using Ctrl C and Ctrl V are the simple answer but the people using this don't want the extra effort and in some cases it is beyond them to even that right.
Create a buttom in the subform and write there a code to start a new record with the same serial as the current record in the subform
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.
Here is my problem and I do not know where and how to start to search about this.
In a MS Access database users will have a list of records returned from a query. Let's say employees which are active (employed). This table has a related table let's say departments (related through departmentID in both table).
What I want to do is to make form (or something else which would do the same job), where user will select some records (probably with checkboxes associated with each record) and there will be a single combobox with department names. When user selects a department name, its departmentID should be saved into departmentID field of these records.
I have created a form with a query of active employees (form with multiple items). And put an extra field in Detail section with a checkbox. In Form footer I have a combobox with Department names and IDs (not shown to user), and a button to save values.
I have to now figure out, how to select all rows/records with a checked checkbox and update them. I am by the way familiar with VB and SQL.
I would appreciate any idea/knowledge on how to solve this.
An extra field in the Detail section won't help you if you don't link it with a data field in the displayed table. If you can do that, then you have simply to make a VBA function to update all selected rows, and refresh the recordset.
If you cannot modify your table, you'll have to create a new table with just the key columns of your master table, and manage it via VBA. Better to use the first option if you can, it pollutes your schema, but in most cases that won't be a problem for an Access database.