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.
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 am using Access 2016, and here is my Access form:
When a new record is created, I need the user to click whether or not the clinical case is true. Moreover, I need the true/false options to be unmodifiable upon clicking and either a trueCase or falseCase instance is created. "True" and "False" will generate the values 1 and 2, respectively, and be stored in the statusTrueFalse field of my Cases table. I don't have any idea of how to proceed from there and would greatly appreciate the community's feedback/hints.
Here is my relationship diagram:
If true, I would like to have the open date/close date and reason closed fields appear. Thank you for your help!
You could change the subform to a list box control with a row source equal to the original subform query.
You could then add macros to the AfterUpdate() event of the list box to show your True/False command buttons (Visible=True) when the user selects a row in the list box. Then add OnClick() events to the command buttons to make them visible=false so they can only choose once.
Add any processing routines to the OnClick() event needed to capture the True vs. False values and store them in your table. You should be able to reference the list box control in your macro/code to choose the correct row in your table to update, or grab other information from the list box to generate a new record.
You might want to add a requery method to the command buttons OnClick() events to also filter any records that have already been answered true/false in the list box to avoid someone re-selecting a row they already answered and adding another True/False record.
Edit: AFAIK Access can't determine which row is selected in a subform, which is why I suggested using a list box instead.
Edit 2 (sorry): I missed your last question. You can have the date fields and reason for closure fields work the same way as your true/false command buttons. Make them visible=false by default and in the OnClick() event for the True command button, set those fields to visible=true, pause your code to wait for entries, then trigger off of another command button or AfterUpdate() event of the last field in your tab order to add the data to your table. Let me know if you need further explanation, I just finished a similar application.
I am trying to set the value of a number field on a table using the value of a bound checkbox on a form. The value needs to be 40 if checked and 0 if unchecked. I'm new to this and have no idea where to start.
No, the checkbox was added to a form and is bound to a number field in the table. The data is imported from an antiquated system that uses codes that most users would not understand, so if it says 40 in the table I just want the form to show checked, all other values should show unchecked, and I want the user checking/unchecking the checkbox to update the table accordingly.
The checkbox is to indicate whether or not a customer has provided direct debit information. 40 would mean they have, anything other than 40 would mean they haven't.
One way do this is using VBA in Access. The way you access VBA console in Access, is when in your form's design view, right-click the checkbox box control and choose "Build Event" from the menu. Make sure your control's Triple State is set to "Yes" in the property for the checkbox in the form's design view. Also, be certain that the checkbox's Control Source is pointed to the field in the table where you're putting the data.
Please note that prior to doing this, it is helpful to prefix your control's name... something like chkDebitInfo... "chk" stands for check box. You can change the name in the property sheet for the control, by clicking on the Other tab, and simply change the default name, which might say something like Check625. Also, you want to set the table field's data type to an "Integer" so it holds the value.
Once you're in the VBA console, after having chosen Build Event... you're presented with the control's sub procedure. I've done a sample for you:
Private Sub chkDebitInfo_Click()
If chkDebitInfo.Value = True Then
chkDebitInfo.Value = 40 // Sets the checkbox to 40 if checked
ElseIf chkDebitInfo.Value = False Then
chkDebitInfo.Value = 0 // Sets the checkbox to 0 if un-checked
End If
End Sub
I've commented the statements that set the checkbox values if checked or un-checked, so you don't have to add those. Just substitute the control name for your's, or use the default name if you haven't changed it, and you're good. Then when the check box is checked or not checked, you'll see the values populated in the database table.
Alternatively, you can set the checkbox to default value for when the form loads, but you haven't stated it, so I won't go into it. Hope this helps. Let me know if I need to expound further.
I have a form with a few bound fields and a few 'custom made' checkboxes, which set values per vba. When I now start a new record with 'DoCmd.GoToRecord , , acNewRec', Access clears my form but won't create a fresh ID until a value is entered into one of the bound fields. Since my checkbox-fields are not bound, any changes before a bound field has been edited won't be saved. I tried adding values via sql statements, but access throws an error after I change another field stating that the current recordset has been changed so I doubt that this is the way to go.
My form is based on a query and witch vba I set the checkboxes like [value_x] = true (which works fine when I first enter data into a bound field and thereby a new record is created).
(Another way to avoid this would be to set any bound field during the onload-event to a value and remove the value afterwards. But that's not very clean I guess ..)
After testing a few approaches I found my earlier stated idea to be the easiest approach. This means I set a value of a bound field in the form_load event and work with me.dirty where neccessary.
Of course I have to delete empty recordsets afterwards (if someone only opens and closes the form), but that can be handled very easy.
Another great idea was the one Robert Harvey gave me. He suggested to add a click event to my unbound custom checkboxes and use this to change a hidden bound checkbox field, which also worked great.
I want to validate a text box
where the user enters the date in format dd/mm
and time hh/mm
in the same text box
how to do this?
There is no simple way to achieve this. There are a couple of complicated ways.
You can make the control unbound, then write a handler for the After Update event of the control. In this handler, you will need to validate the user's entry, create a date value from the entry (presumably defaulting the year to the current year), and assign that value to the field storing the date. In addition, you will need an OnCurrent event on the form, where you will set the value of the unbound control to be the appropriately-formatted text version of the date of the current record.
Note that this method won't work in a Continuous form, only on a Single Form.