Regarding access 2007 querys - ms-access

I have built a form called projects and an employees table in access 2007. One of the fields on the form is called installers sent. I would like the installers sent box to auto populate based on the first name of the employee in the employees table. How can this be done? If I need to put in more clarification, I will. This is my first time working with access so I'm not really sure what i'm doing
Edit: I'm not sure what you mean by code. But basically, I have a table that keeps track of employee info and another table to keep track of project details. Both also have an associated form for easy data entry. On the projects table, I have a field for which installers were sent to the project site. Obviously, all these individuals are also employees. What i'd like to be able to do is have employee information auto populate as the user types in an employees first name. I'm assuming I can set up a query to do this, but I'm not sure how

Your question is still somewhat confusing to me in that you only mention two tables but multiple installers (employees). This suggests that you need three tables:
Projects
ProjectID
Employees
EmployeeID
ProjectsEmployees
ProjectID
EmployeeID
This could then be set up as a main form and subform: Binding a combobox in subform Access (prettier subform Difficult cross-tab query)
An alternative is a listbox with the row source set to:
SELECT EmployeeName FROM Employees
INNER JOIN ProjectsEmployees
ON Employees.EmployeeID = ProjectsEmployees.EmployeeID
WHERE ProjectsEmployees.ProjectID = Forms!TheCurrentFormName!ProjectID

Related

how to assigne correct client_ID to order record from name, adress or create a new one if it doesn't exist

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

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.

Syncing employee list with activities during the week many to many relationship

I have a form where you choose the employees in a dropdown continous form.(From tblEmployee) that worked this week and store them in TSLabor table. In another form I track what activities were done during the days of the week (could have multiple activities for any given day) in tblActivities. In this form I have a sub form list of all the employees who are in tsLabor for this week. This way the user can input the hours for each employee. (Not all employees will have hours in every activity, but I can handle zero hours.) These records are stored in tsActivityLabor. I add a record for each employee in the TSLabor table with the activityID it each time a new activity record is created.
User can not add/delete in the subfom, but they can in the First form. My issue is how do I add/Delete from the tsActivityLabor table (for each activityID) when an employee is added/deleted from the First form.
I need to check to see if the employee has a record for each activityID for that week. If not add it.
Right now I create a record set of activityIDs for the week from tblActivities. I then create another recordset from the tblTSLabor of all the employees in that week. I then take each ActivityID from the first recordset and create a third recordset of all the employees for that ActivityID in the tsActivityLabor table. I then verify that each employee from the second recordset has a record in the third recordset.
There has to be a quicker way of doing this but I can't figure it out. One thought is to create an update query that could look at the tsActivityLabor table and verify that there is an employee record for each employee for each activity. Researched but can't find any examples of a query like this. any help would be appreciated.
Adolph
In short when queries underlying forms get complicated Access doesn't know how to update the tables and so chooses not to try.
https://learn.microsoft.com/en-us/office/troubleshoot/access/errors-updating-query-form-data
This is not a problem for your case as the TSLabor table in your example can be replaced by a date column in the TSActivityLabor Table. Access is supposed to be user friendly so I'm going to suggest a workflow that lets access help. here is an example:
create the following tables and hook up the relationships under the Database Tools-Relationships Tab.
Now click on any table and hit create form and access will create a working form which properly updates the tables. Here is the form after hitting the Employee table:
Because we set up the relationships in advance Access automatically added the many side of the relationship as a subform. Play with the highlighted record selectors to see how to cycle through records and add new ones.
Next we Start improving the forms. In the EmployeeActivity Form I Replaced Foreign Keys with combo boxes, removed the ID which the user should never see and added an unbound combobox to filter the records.
P.S. if the weekly Activities is still a thing Relate Activities to employees through a weeklyactivities table (a type of super many to many relationship).

How to select multiple records and change their value at once

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.

MS Access Report showing the id of the combobox and not the bound name column

The company I work for have an access database that is linked to a sql server table. The database is on a shared network location so it is used by lots of people in the company (with the annoying problem that only one person can use it at a time).
There are several forms that are used as a front end for the data and on one particular form there are combo boxes that are linked to other tables.
When a report is generated on the form the ID of the combobox is on the form (a GUID) and not the bound item of the combobox.
How can I get the bound items to appear on the form itself? The solution needs to be easy to do or something i can produce that can be regenerated as it's used by non technical people.
In order to make the database usable by many, simply give each user a copy of the front-end.
Forms should almost never be used for reports, the best thing to do is to build a query (the query design window will help) that references each of the relevant tables, for example, if the combobox contained a reference to person type and you might build a query like this for your report:
SELECT a.ID, a.SName, a.MainAddress, c.PersonType
FROM Addresses a
INNER JOIN PersonTypes c ''Or LEFT JOIN if data is missing
ON a.PersonTypeKey = c.PersonTypeKey
If this is not possible, perhaps you could explain in more detail exactly how the report is generated from the form.