retrieving data from a query inside a form - ms-access

I have a form in MS access which contains information about customers of a store (It's directly connected to the table because I want to be able to edit fields).
I want to have a field inside the form which contains information calculated in a query in the form of (ID, Value)
How is it possible?

Derive data using either VBA or Macro

Since your form is bound, and the field in your query is not a field in the bound table, you can simply add an unbound control to your form. You can use a textbox control, draw on form, and it should default to an unbound control. To check, select the new control and confirm that its control source property is blank.
I am assuming that your query already has form references that are filtering the results based on which record you have open on the form. If not, you will want to put in the ID field's criteria of your query: [Forms]![MyForm]![MyBoundIDControlNameOnForm]
In your form's On Current event. Open the code builder and type this into the On Current event:
Me!txtMyNewControlName = DLOOKUP("[Value]", "MyQueryName")
DLOOKUP has a third argument that allows you to add criteria. I am assuming that your query only returns a single row with the form reference criteria, so there is no need to tell DLOOKUP which row in the query results to return.

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.

Ms Access Datasheet view - only one column editable

There is access datasheet sub-form and users should only be able to edit count column. How can that be done ?
Currently, If I change the form property Allow Edits = True, users can update any cell.
Also, the user should be able to enter different count values. If a user types 1 in first cell, it get copied for all the rows.
How can this be achieved?
For each control on the form that you don't want editable, set the Enabled property to False (or the Locked property).
For the count copying to all rows, we need to see the query that this datasheet is based on to answer that. If the count is an unbound textbox, you will get the behavior you are seeing as Access will only create a single instance of the control, then repaint that single instance across all rows (note that this is the same with continuous forms as well)
Instead, create a query that has this field (or a dummy table) and bind to that, making sure to bind the textbox to the dummy field, and then you should be able to edit the value on a per-row basis.

Updating a non-bound field in a form with a record source

I have a form with a record source of SELECT [AccountRunInProgress] from [AccountRunSummary]. The form contains a text box with a date which is used to apply a filter on the above record source, based on the month and year (defined as two separate fields in the AccountRunSummary table).
The other field in the form is a check box bound to the AccountRunInProgress field. When ticked, the OnClick event for this box updates a date field called RunProgressStartDate in the AccountRunSummary table with the current date and time.
I then get a Write Conflict error when closing the form - almost certainly because I am trying to update the table via the OnClick event while using the table as the record source at the same time, despite not binding the date fields. The date is updated in the table but not the boolean.
What is the best practice for working around this? I thought about adding RunProgressStartDate as a hidden bound text box in the form and adding it to the record source, but I'm fairly sure that will cause more problems rather than less.
You are on the right track.
You can't edit a record through the bound form and with an Update query (in VBA) at the same time.
IMO the best solution is indeed to add RunProgressStartDate to the record source and as hidden control to the form.
Then (important!) set the value of this control in the OnClick event, don't write the table with an Update query:
Me!RunProgressStartDate.Value = Date()
and both fields (checkbox and date) will be saved when the record is saved.

Textbox calculation appears only after navigating through other records in access

I have a form that is linked to a table in Access. I have an additional field which displays the sum of a few fields in the table. This field on the form is not connected to the table. I have the sum displayed on the form but what I noticed is that the sum does not appear until I move away and navigate to another record and come back to the original record. I don't see the addition as soon as I enter values in the respective fields.
Can someone help with this issue?
It sounds like you need to add some code to the After Update events of the controls for the fields used in the sum. That code can call the .Refresh method of the control that performs the calculation and update the total.
Edit
Another possibility is that there could be ambiguity between control values and field values if they have the same name. In Design View for a report if you drag a field from the "Field List" and drop it into a report then Access creates a report control with the same name as the field. This can confuse matters later because if any expressions refer to =[SomeColumn] it's not clear whether that refers to the field or the control. Often simply renaming the controls to something like txtSomeColumn can help if a report is acting strangely.

how to display specific records for editing in MS Access

I need to display certain record (all the fields in the form populated according to that record in the form) according to textbox in form. Is there a way for me display that record without using filter or vb code? Do i need to design a query for this?
Yes you can put an unbound textbox (or combobox) in the header of the form. Then change the recordsource of the form to a query, just click the elipsis (...) next to the table name in the record source property and access will open the query design window for you.
You need to add all the fields to the query and in the Criteria row of the field you want to select by right click with the mouse and select "Build". You will be able to select the unbound textbox.