Validation Problem in vba text box - ms-access

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.

Related

MSAccess Change Date Value Before Validation

In a grid I have a date/time field where I would like the user to be able to type in short-hand formats for dates and times. For example, if they type in "435p" and then focus off of the cell they get the message "The value you entered isn't valid for this field.". Instead, I want to trap a pre-validationevent and change it to "4:35pm" for them.
What event can I use?
I've tried:
LostFocus & BeforeUpdate: too late (validation fires before event)
Dirty & OnChange: too early (they haven't left the cell yet)
Or is there a way to turn off the native validation rule that is checking for date formats?
You could use an additional text field without formatting (or with your very own format). Then show this instead of the datetime-field and update the date-time field with your code.
Not very pretty, but if you always format the input to a proper time string on before-update and never access this field (but rather the real date-time field) you should be ok. You could even name the field Helper_DateTime or somesuch, so you are never tempted to access the field from anywhere else ;)

Passing Parameter to next form starting with parameter input dialog

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.

Bind Textbox To a Field

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.

Get the value of textbox after refreshing the 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...

Linking a Checkbox to date

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.