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.
Related
I have a report that has three params. one is dropdown. It created automatically when i supplied
name and value, Then If we select multivalue, it shows multivalue dropdownlist.
But I am not able to create a textbox. That will act as a parameter to be supplied in report.
for that I have created a parameter, set it to allow null and datatype = "text" .
parameter visibility is also visible but as a result I can see a textbox which is a disbled one.
How can this textbox be made to work?
While in the Report Parameter Properties for the text field in question, chose Allow blank value (rather than Allow null value). In the Default Values section of the properties dialog, choose Specify values, Add a blank default value.
Now you will have a working text field that the end user can type into, and you can use that value for searches in your query.
Hope this helps
To allow user to enter the parameter value manually:
Right click on the parameter and select Parameter Properties
On the Available Values tab, select None
Click OK
Now users can manually type in the parameter value.
Click to see screenshot
I'm not really sure how to define this.
I have a table that has a few fields, let's call them: ID, Name, and Type.
I have a form that allows the user to add new records via Datasheet view. ID and Type is hidden, and only Name appears. I've setup a Filter that shows only records of a specific Type (i.e. Type = 2)
However, if someone enters a new record into the datasheet, the Type field does not get set. Setting a default value on the field won't accomplish what I want because I have a few Forms that are tailored based on Type, therefore, each needs to submit new records to the same table based on that type.
Is there a way to define what value it should set Type to? I guess I could capture the BeforeUpdate event, and set the value that way, and just hide the column. I was wondering if there is a way "proper" technique, though.
In the form's Before Insert event, you can examine the current Filter expression, parse out the filter's Type value, convert it from a string to a number, and finally assign that number to the hidden control which is bound to the Type field.
So, assuming that hidden control is a text box named txtType, and its control source is a long integer field:
Private Sub Form_BeforeInsert(Cancel As Integer)
Me.txtType = CLng(Split(Me.Filter, "=")(1))
End Sub
Use the appropriate type conversion function in place of CLng() to match the bound field's data type.
That approach should work if you're setting the Filter like this:
Me.Filter = "[Type] = 2"
Me.FilterOn = True
But, if you're using a different method to do the filtering, please give us details about it.
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 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...
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.