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...
Related
So I have some textbox on my form,and on the last textbox, I turn off the enable so instead of asking the user for the input, I want to make the value on the textbox calculate automatically when the user input on another textbox, so I set the default value like this :
=IIf(IsNull([jmlh]),0,[jmlh]*[harga]*IIf([diskon]>0,[diskon],1))
But the problem is the expression just work when the form loaded, it's still not when value in "[jmlh]" change. Is there any method or something to make it possible?
Don't put your expression into Default Value, but into Control Source property.
Then it will always update itself when one of the used fields changes.
If it is a bound field (but why would you want a calculated field stored in the table?), you need to put that formula into a VBA function
Private Function UpdateCalcField()
Me.calcField = IIf(IsNull([jmlh]),0,[jmlh]*[harga]*IIf([diskon]>0,[diskon],1))
End Function
and call that function from the AfterUpdate events of all involved fields.
I'm trying to create a database that is user friendly. So far I've developed two forms.
Form 1 shows an overview of orders. Form 2 shows the details of a specific order. Form 2 is build on a query that retrieves information from different tables.
When I open form 2, a parameter input dialog box appears asking me which ordernr he has to look for. When I type in a number, the specific details from that record are shown.
Now comes the tricky part. form 1 shows the overview. When i click on an ordernr a textbox is filled. I did this to confirm the program reads the right number.
My question: How do I get the number from my textfield in form 1, into the parameter input dialog in form 2? The numbers are stored as text so no conversion is needed.
I saw a lot of solutions with DoCmd.OpenForm "Formname" ,,,,,, OpenArgs. I do believe this can be the sollution. I just don't know how to get OpenArgs into the Parameter Input Dialog.
Thanks for helping!
Change the query of the second form to have the value of the text box that you populate as a filter on the ordernr field. You might also to set the 'Modal' property of the second form to 'True' as this will prevent (or hinder at least) unsynced forms.
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.
I want a text box to contain data which is a calculation based on 2 other control field values - only if it's value is null (ie the current value of the column in the database is null).
So I entered =([control1]*[Control2])/1000 in the expression builder for the default value property - however the result always shows the textbox to be empty (even tho control2 and control2 contain values).
How can I achieve this? Can such an operation only be done in code-behind ie VB??
thanks,
KS
I think you're talking about a control bound to a field in the form's record source. And when the underlying field is Null, you want the control loaded with your calculated value.
If that interpretation is correct, you can do it from the form's On Current event.
If IsNull(Me.txtYourTextBox) Then
Me.txtYourTextBox = (Nz(Me.control1) * Nz(Me.Control2)) / 1000
End If
That will load the computed value into the text box, allow the user to change its value if desired, and store the value to the bound field when the record is saved.
If the bound field is not Null, its value will be displayed in the text box without alteration by the On Current code.
Is that what you want?
To accomplish this using VBA, add a Form_Load Event. (Open the form in Design View and in Form properties click the Event tab and choose Event Procedure for "On Load" and click ...)
This example uses [TextField] to refer to the table data.
Private Sub Form_Load()
TextControl.SetFocus
If IsNull([TextField]) Then
TextControl.Text = ([Control1] * [Control2]) / 1000
End If
End Sub
I am trying to link a checkbox to a date. So when the user Clicks the checkbox it automaticly puts in the current date.
In the AfterUpdate event of the CheckBox control you'd add this code, where chkCurrentDate is the name of the checkbox and txtDate is the name of the textbox bound to the date field:
If (Me!chkCurrentDate) Then
Me!txtDate = Date()
End If
Now, you haven't specified what you want to happen if the check is already checked -- change the date? Remove the date?
This leads me to the next point:
I'm not sure you've chosen the right controls to do this.
If you use an unbound checkbox to populate a date field, you're using it like a command button. I would suggest that a command button makes more sense.
But that might not even be necessary -- it depends on what is triggering the need to enter the current date. If you want a new record to be stamped with the current data, you could use the .DefaultValue property of your control that displays the data to the Date() function (or, in the field definition in the table, set the DefaultValue to Date()).
But it might be that you want to stamp the record with the current data because it's being updated. In that case, you'd use the Form's BeforeUpdate event to set the date value.
And it might be that your checkbox is, in fact, bound to a field in the form's recordsource, in which case, you really would need to determine what to do if the check is cleared.
Perhaps you could describe what your form is editing and what process is triggering the need to enter the current date and then determine better which of the many possible approaches makes the most sense.