set field value based on other fields values - ms-access

I'm trying to create a validation rule in Access 2010 to set the value of a true/false field to True...
More details, I have a table with several yes/no fields and one true/false field and I want the true/false field to change to true only if all the yes/no fields are yes.
I'm trying to make it that it is set automatically after updating the fields and without the user changing it...

A Validation Rule can not alter a field's value. It can only indicate whether or not that value should be considered valid.
If you want a field which automatically updates itself to indicate whether other fields are all True, consider a calculated field or a data macro. Since you're using Access 2010, both those options are supported.
However, a simpler approach would be to decide you don't need that summary field to exist in your table design. You could use a query to derive it whenever you need to see it.
For example, with two Yes/No fields Fld1 and Fld2, a simple field expression will tell you whether both are True ...
SELECT Fld1, Fld2, (Fld1=True AND Fld2=True) AS all_are_true
That would present True as -1 and False as 0. If you want the query to show those values as True or False, you can use a Format expression ...
SELECT Fld1, Fld2, Format((Fld1=True AND Fld2=True), 'True/False') AS all_are_true
That computation is a trivial workload for the db engine. And computing the field expression each time you run the query ensures all_are_true reflects the latest changes to the other fields.

Related

MS Access-Using value from a form in a calculated field of a table

I have a text box in a form which accepts a date.
I have to use that date in the calculated expression in a field of a table.
Initially I have tried to use this statement in the calculated expression.
[Forms]![Input data form]![Text38]
But it shows that "The expression cannot be used because refers to another table".
How to access the value of the text box?
I think I understand your question. You have a table and you want to use a calculated field in it that references a value in a form.
You will not be able to do it that way. The reason you are getting an error is because the form data only exists when the form is running. If you used that expression in the record source query of the form, you would be ok.
You have a couple of choices depending on what you are trying to do with the data. If you REALLY NEED a calculated field in your table, you can use a form to make an UPDATE to another field in your table; then it is static data and your calculated control can work.
Another option is to have a separate table to store the user input value, then use a VIEW (QUERY in Access terminology) to join the data together and compute the result. Depending on why you are doing it, this is typically the method you want to go with.
If this does not answer your question and you have something more specific, I will try to tailor the answer more.

Update Table Column off of Query Column

I am trying to Update a column in my table Inputcounts called concatenate off of a query called InputConcatenates that has a column also called concatenate. I am running an update query with the field name as concatenate the table name as InputCounts and the update to field as [InputConcatenates].[Concatenate]. But every time I run the query it pulls back that 0 records will be updated. Is my syntax wrong possibly?
Update Query SQL:
UPDATE InputCounts INNER JOIN InputConcatenate
ON InputCounts.CONCATENATE = InputConcatenate.CONCATENATE
SET InputCounts.CONCATENATE = [InputConcatenate].[CONCATENATE];
InputConcatenate Query SQL:
SELECT InputCounts.FLEET, InputCounts.AMMs, [FLEET] & [AMMs] AS CONCATENATE
FROM InputCounts;
You reported this query accomplishes what you want ...
UPDATE InputCounts
SET CONCATENATE = [FLEET] & [AMMs]
WHERE CONCATENATE Is Null;
That may be fine. However CONCATENATE is not updated until you execute the UPDATE, and does not get updated (after having previously received a value) in response to changes in FLEET or AMMs
Decide whether CONCATENATE really needs to exist as a field in your table. You could use a query to derive it whenever you need it:
SELECT *, FLEET] & [AMMs] AS CONCATENATE
FROM InputCounts;
With the query, CONCATENATE will always be up to date.
If your database is ACCDB format and your Access version is >= 2010, another possibility is to make CONCATENATE a "calculated field" type in the table's design:
If you prefer CONCATENATE be Null whenever FLEET or AMMs is Null, change the field's Expression property to [FLEET] + [AMMs]
The advantage of a calculated field is that Access automagically updates its value without further effort (like executing an UPDATE) from you.
A disadvantage is that you can't index a calculated field. That means it's not suited for joins, WHERE criteria, ORDER BY, etc. You'll have to decide whether it's a reasonable fit for your application. :-)

Display specific records depending on user's choice

I have a MS 2010 Access Report that needs to be populated by records that a user pre-chooses. For example.
Form1 has 2 fields, LOT# (which is record id) and CheckoffBox (unbound).
User checks which Lot#'s (records) he wants displayed, then clicks REPORT button. Report only shows selected records.
Can someone help me create the code?
In order to allow the user to use a check box to select multiple records, the list presented in form 1 must be based on a table that has LOT# and a yes/no field. (ie form 1 must be based on a query or a table that ahs this yes/no field).
If only one user will ever use this at any one time then you can simply add a yes/No field to the table that has all the LOT# values.
On your report you then only print those lot numbers that are checked.
Your report simply has to have SQL with a where clause that only print records that have the Yes/No field ticked. (=true =-1).
If many users are going to use this form at the same time it gets more complicated as obviously they all need to have their own "set of yes/no fields".
So you would need to copy the table with the LOT# into a temp table for use by each user (it might have a primary key of USERID, LOT#, or it might be a table with just LOT# and yes/no fields, that only a user can access - ie in their own copy of the database file that has the front end forms).
Anyway, assuming it's a single user, creating the above should be quite straight forwards.
On opening form 1, you might use the form_open event to run a SQL statement that sets all the Yes/No values to No. Although you might not want to do this.
Use
docmd.SetWarnings false
Docmd.runsql "UPDATE theTable SET YesnoField = 0 WHERE YesnoField = -1;"
docmd.SetWarnings true
Let me know if you can take it from here.

How can i run the report without specifying the parameter value in SSRS

H, I have a parameter 'Client' as drop down in SSRS report. My requirement is to select all the records for all the clients if i don't select any parameter value and if i select particular value in the drop down,i need to display records for the that particular client.
I am getting the list of clients as a input from query.How can i add option select all by default.
Thanks in advance
You can do this a few ways...
Check the "Allow Multiple values" on the general tab of the Parameter Properties, go into the Available values and select the dataset you are using to get the values, make sure the the column that contains the actual data to search on is what you select for the VALUE field...(with this one - make sure your query eliminates the NULLs for the Value field) then you will have a drop down with all the values and it will add Select All...
Then in the Default Values tab, you can hook to the same query and select the VALUE field again... (as long as there aren't any NULLS) You may need to do tweaking depending on your query and values...
or
You can check the "Allow Null Value" on the General tab in the Parameter Properties, then in the Default Values - select "Specify Values", then Add, and (null) pops in there automatically...
Then call a stored procedure where the parameter defaults to NULL and if you pass NULL or don't pass in a string of values, your query will return all (not sure how you'd implement this if your query is embedded in the report... I try to do all of mine in Stored Procedures..)
Add "All" to the results of the query that returns a list of clients for the drop-down and make it the default selection. Then handle it in your main stored procedure that if "All" was selected, you don't filter by clientId, and just get all clients.

Form Recordset in Access 2007 Returning no data

I'm building a form in access that has a several sub-forms in a tab control The sub-forms are working fine, but when I set the parent form's Record Source property and bind a few Text Boxes to the data, I find that a null recordset has been returned.
I've tried this with several different queries (each of which works in a separate query designer) to no avail. I've also tried binding the form to a Table directly and a null recordset is still returned.
I've checked the filters and they are turned off.
If the Text Boxes that are bound to data are Locked and Disabled then the query will return a null dataset by default.
The form's 'Data Entry' property also needs to be set to false. Setting it to true will make the form for data entry only. This prevents any data that might be returned by the background dataset from appearing when the form loads.
Have you tried executing a Requery on your parent form:
Me.RecordSource = "someQuery"
Me.Requery
?
Can you unlock and/or enable the fields before setting the data source?
Try checking the relationships in your tables especially if you used the auto "look-up" option to create a relationship.
Open your tables in design view and check if your foreign keys(FK) are indexed appropriately or not (under field properties).
If they are indexed, ensure you have the correct type of index for that particular field. Example; TABLE A with following columns PatientID(PK), PatientName and TABLE B with columns ID, PatientHeight, PatientWeight, PatientBP, PatientID(FK)
For such Table B, if you have the "PatientID(FK) indexed with "duplication OK", you will get RecordSet error when using those fields related to this table in the form especially if the form JOINS fields from multiple tables.
In summary, try checking the indexing of your fields especially if they correspond to their type of relationship