Show Sum of query results based on main form in text box - ms-access

I have created a basic database in Access 2013 for project management.
Therein I have set up a main table called Project-properties which holds Project ID as a unique identifier and other fields for project properties. This table is linked via a 1:n connection to another table called Invoices which holds all invoices corresponding to a unique project.
I then went on to create a form based on the Project-properties. On this form I want to display a text field showing the sum of all invoices corresponding to the selected project.
Imagine I have 10 invoices spread across 4 projects, with $10k each resulting in a total of $100k. What I want show in the form is only the sum of the invoices corresponding to, let's say project ID 01. In the Invoices table, only 3 quotations correspond to this project ID with $10k each, so the aforementioned text field should show $30k.
I have tried with =Dsum('InvoiceSum';'Invoice') but I only get the sum of all projects $100k.

DSum (and associated domain lookup functions) have a third argument that allows you to specify a filter.
If the project field is a string, then you would use something like:
=DSum("InvoiceSum","Invoice","ProjectID='ID01'")
If you wish to have the filter dependent on a variable, then this would become:
Dim strProject As String
strProject="ID01"
=DSum("InvoiceSum","Invoice","ProjectID='" & strProject & "'")
If this is a control on a form, and the Project ID is numeric, then you would use this as the control source of a text box, as long as ProjectID is included in the Recordsource of the form:
=DSum("InvoiceSum","Invoice","ProjectID=" & ProjectID)
Regards,

Related

Creating parent child label columns in SSRS

I have a stored procedure and an ssrs report that takes work orders of a certain category (user entered parameter, ex. A,B) and then selects other work orders of the unselected categories (C,D) that are within a user entered buffer distance (parameter). The listing that the report generates contains a Primary Work Order Id field (Primary WOID) and a Buffer Work Order Id field (Buffer WOID). I need to create a single column that indicates the parent/child (Primary/Buffer) relationship as well as well as the grouping of the records. The screenshot below is an example of what I would want the new column to look like.
desired column in listing report. I'm using Report Builder 3.0 and SSMS v17.2 .
If you dont have a sort order your created key, like you want to do it, could be different every time. Or if you load more or less data you get the same problem.
You should just concatenate the fields and thus creating your key. For example if you concatenate the columns Primary WOID, Buffer WOID, Priority Category:
=Fields!PrimaryWOID.Value & Fields!BufferWOID.Value & Priority Category
Result:
8944925B
89449256570374C
89449258145995C
8944920B
...

Autofill fields in Access Form

The Scenario
I am designing a database to digitize many carbon records of different fish, the prices, quantity sold, and the selling firm.
I have one table called MainFishNames with a field called CommonNames (the names that will be entered in the form) and a field called CategoryID, and another table called Category, with 2 fields: Category, and CategoryID.
The Goal
For ease of data entry, I am trying to program a field in the form to autofill to the fish category i.e. Pelagic, Bottom, etc... based on the fish name they enter in another field.
The Issue
I've already successfully programmed another field to autofill the firm name based on the firm ID using DLookup in the control source, but I haven't figured out how to do the same for when I am not looking up a value based on an ID.
Every time I try this using DLookup I receive an Error in the field. Is this possible using DLookup, or should I go about this another way?
Thank you
If I am correct that MainFishNames contains a field called CategoryID that is the FK for the Category table, then you will need a nested DLookup to first find the CategoryID, then use that as the criteria for the Category Name:
=DLookup("[Category]", "Category", "[CategoryID] = " & DLookup("[CategoryID]", "MainFishNames", "[CommonNames] = '" & Forms!Prices!Combo43 & "'"))
That being said, using DLookups can impact performance, and might not be advisable for every control. If your form is bound to the MainFishNames table, using a subform bound to the Category table should be a simpler and faster solution.

SSRS Report Expression, for 2 fields in one column

I'm creating a report, and I'm trying to have two fields displayed one or the other in the one column= Account Name.
See my problem is, if I run the report with one of fields some some of the account names are populated
For example:
Table 1
Table 2
If I use 1 set of Account Name and Address fields, only some Name/Address fields are populated like in Table 1.
If I use the other set of Account Name and Address fields, only some Name/Address fields are populated like in Table 2.
How can I use the 2 sets in an Expression, so that all the Name/Address fields are populated.
I've solved it,
=Fields!Addr1.Value & IIF(IsNothing(Fields!Addr2.Value),"",VbCRLF & Fields!Addr2.Value)

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.

InfoPath 2010, read & write to Access 2010

I have an InfoPath 2010 form that I've created to submit data into an Access 2010 database. One specific element being captured is an employee ID. So, the database may have multiple records of the same employee ID.
I have a second table in the database, that contains every employee ID in one column and their name in another.
If the user is creating a record for employee ID 987, how do I add a textbox to this form that will read the corresponding name found in table 2?
Thank you,
Jeff
Here I am using this procedure in fetching data from list. Try whether its working for Ms Access
If you need to fetch data using infopath2010 then use following condition
In the Rules add Action
Under Run these action add Set field value
In field box select where fetch details wand to display (i.e which txt box)
Click Calculted value (fx) in value
In that click insert field or group and select Show advance view
Under field select which table you need to fetch the data
Select the field which you need to display in the selected txt box and using filter condition filter the data using secondary table employee id= employee id in main field
Secondary table will visible in infopath form only if you get connected with that using manage data connection in infopath