I have a form in MS access. I have created a few textboxs in that form. I have input a function in the control source property of a particular textbox(TOTAL). This basically sums up numbers entered by the user and displays it in the textbox.
The problem is the textbox is unbound. I want to bind the textbox to a field in the table using vba code. I could have just bind the textbox by the putting the table field name in the control source property but it is occupied with the SUM() function.
I not sure how to proceed here. I have tried searching up on the web for several days but failed to gather a reasonale solution.
Please help
You need to remove the sum function and put that in a suitable event for the form or event for another control and then bind the textbox.
As a general rule, you should not be storing calculated values, it is against the rules for normalization.
Related
I drag an drop a simple query without any criteria in a form.
I want to filter data (like FamilyName) via textbox in form through OnChange event.
Here the question: how can i filter query data with value of textbox?
If your query now appears as a subform in your form, use the MasterLinkFields and ChildLinkFields properties of that subform control:
As MasterLinkFields: [NameOfYourTextbox]
As ChildLinkFields: [NameOfFieldInQueryToFilterWithValueOfYourTextbox]
ON the After Update event of the textbox, you can set the record/row source of the query and/or subsform. You'll have to use vba to do this, but its a relatively simple task. Without any examples I can only give you the high level answer.
I am looking at the following post SO Question and am struggling with how to perform the answer to the question:
The way that I ended up solving this was to add a field to T, and have that field updated during the AfterUpdate() event with the value from the DLookup() call. Because the field is now no longer query-based, it can be used to filter the form.
Specifically, what are the steps to update the 'table field' with the value from the DLookup() call? Do I place the DLookup in VB code?
I always prefer using vb codes but that is because I don't feel as flexible in the things I want to accomplish using macros. However, if you don't want to use VB code you can create a bound text box that captures the value of the unbound DLookup. then have the bound text box set to visible = false. that way you will not have two box with the same information on your form.
I have a continuous form that has the property that has some fields.
When I click a button on the form a Requery is processed on the form which results in updated value of some textboxes (these are not enabled, i.e. read only).
What I'm trying to do is to get the value of one of the textboxes in the form after Requery.
How do I do that?
I've tried using the Current event to get the value after the requery (refresh) but it's not working. Is there any other event that can do the work?
Just use the name of the field. For example, after the requery, use msgbox [FieldName].
Thanks for your contribution..
The problem was that the value of the field I was trying to get the value of comes from adding 2 values (a + b)
and so the solution was updating the field before saving its value to a different variable...
Guys...if I want to run a button click event that takes a list box and uses the ID field that is in the listbox in a SQL statement in VB, then is it
me.MyListbox.selected
or
me.MyListbox.value
to get that value? for some reason I have tried both and neither seem to be working. .value returns an empty value, and .selected generates an error stating the argument is not valid.
thanks
justin
If the ID is the bound column and the listbox is not multiselect, you can use just the name of the listbox without any other qualifier. If the ID is not the bound column, then use the column property to get the value : MyListBox.Column(n) where n is the column number starting from zero.
For multiselect listboxes, you need to iterate through the selected items to get a list to use with SQL.
If you are using the query design window or a control on a form or report, you cannot use Me, you must either use the full reference (Forms!Formname!ControlName) or for a control on the same form, just the name of the listbox.
I'm trying to display the sum of a field in a text box in the form footer. The field is not calculated in any way.
Here are a couple of the things I've tried:
=Sum([txtWeldInches])
=Sum([WeldInches])
=Sum(CDbl([txtWeldInches]))
=Sum(CDbl([WeldInches]))
...well you get the idea. Each iteration I've used results in the Text Box displaying #Error Without exception.
I've used similar constructs in different forms in the same project, so I'm not sure what the problem might be.
Has anyone run into this before?
EDIT:
I ended up writing a VBA routine to update the boxes when it was likely that they would be changed rather than trying to get a bound sum() function to work.
http://support.microsoft.com/kb/199355
All of the domain functions are based on the same query (over the underlying recordset). If one of the bound functions on the form has a binding error, all of the functions on the form will return an error.
In other words, make sure all your footer controls are resolving properly and not hitting any nulls.
If you use a SUM or AVG then make sure you are also using the Nz function:
ControlSource = =SUM(NZ([FIELD],0))
Is the field "WeldInches" existing in the data source for this form?
What datatype the field "WeldInches" is?
EDIT: I have looked at all your comments. If it doesn't work by databinding, try and use the unbounded way. At runtime, get the value of WeldInches using DSUM and set the footer textbox's value when the form loads.
Also, remember to update it at places where you think the SUM could change.
I had the same problem as Rister.
The source of the form was an underlying query.
I had a bound text box named txtQty on this form. Its control source was Qty (based on the underlying query of the form).
I created an unbound text box and entered =SUM([txtQty]) and received an error.
I tried various ways to find a solution and was very desperate.
Then I deleted the underlying query and created a new one using the same name and fields as before.
Then I entered =SUM([Qty]) into the unbound text box on the form and voila, it worked. Note that I didn't enter the name of the bound text box (txtQty) into the expression, but its control source (Qty). I don't know why, but it worked for me.
I know you said "Form" but for those who have issues with the Sum formula in an Access "Report" the formula has to be in the Report Footer NOT the Page footer. Took me a while to figure it out as Access defaults to only showing the page footer.
You want to sum by the name of the column in the record source: SUM([WeldInches])
Make sure there are no other textboxes with the name WeldInches.