Hi Guys
How would I write a macro (step by step guide) so when a user presses a button it inserts the current date and time into the field?
Best wishes
Hi Guys
How would I write a macro (step by step guide) so when a user presses a button it inserts the current date and time into the field?
Best wishes
With your form in design view, highlight the button.
With the property sheet for the button visible, find the "on click" event. Click on the ellipsis (3 dots) and you should get a box which allows you to choose "code builder".
A visual basic form will pop up with something like
Sub Yourbutton_OnClick()
End Sub
Between the sub-end sub, put
me!textboxname = now()
This assumes that you are displaying a textbox on a form.
That's fantastic! And thanks for the step by step guide.
But... I need it to insert a new date/time on a new line every time the button is pushed. How can I manipulate the macro to do this?
Are you really wanting to insert the date/time into a table field? Maybe you need to put the expression in the default value of a table's field and forget the button.
Basically I have a 'notes' field and the user will be adding notes and dating them as they go along.
There will be mutliple notes in the field all with multiple dates on them. How can I achieve this?
On button click
me.textbox= me.textbox& " " & Year(Now()) & "/" & Month(Now()) & "/" & Day(Now())
However, it seems to me that a better design would be a notes table, consisting of UserID, Date, and Note fields
This is returning a syntax errorCode:me.textbox= me.textbox& " " & Year(Now()) & "/" & Month(Now()) & "/" & Day(Now())
I often post from a computer that doesn't have Access on it, so my answers aren't checked for syntax. Having said that, I'm posting from that computer again, and the error that I see is
me!textbox = me!textbox & " " & Year(Now()) & "/" & month(Now()) & "/" & Day(Now())
Also, "textbox" is meant to be your textboxname, not literally "textbox"
My apologies.
Hope this works for you.
That's perfect, thanks so much for your time.
One more thing, is it possible to insert each date on a new line? I've got Enter Key behaviour set to new line on this field.
It appears that you are using the button to insert the current date into a new record.
(As I mentioned previously, you could do this by setting the default to Now(). That wouldn't change records with blank entries or nulls, but it should show the current date on new records.)
Are you asking if the button click will work with each new record? I think it should.
Will it work multiple times for multiple entries into your notes? I don't know. I think it could be made to work, but I'm minimally understanding the exact sequence and your criteria.
On each record there is a field. At the moment pressing the button multiple times will insert the date into the field as many times as you press it. That's perfect, I'm just wondering if it's possible instead of it going [Date][Date] it'd go [Date][NewLinewithinfield][Date]
You could conceivably stretch the characters on out by continuing to add text and other control information... AddingOn each record there is a field. At the moment pressing the button multiple times will insert the date into the field as many times as you press it. That's perfect, I'm just wondering if it's possible instead of it going [Date][Date] it'd go [Date][NewLinewithinfield][Date]
& Chr(10) to the previous code would insert a newline character. I believe Chr(13) is a return character. Not sure whether you need one, both, or something else entirely.
NeitherorCode:Me!Text30 = Me!Text30 & " " & Day(Now()) & "/" & Month(Now()) & "/" & Year(Now()) & Chr(13)is working ;'(Code:Me!Text30 = Me!Text30 & " " & Day(Now()) & "/" & Month(Now()) & "/" & Year(Now()) & Chr(10)
Please help?
Tell me where we are, i.e. a click button puts the date into a textbox field that is being stored in a table?
But it isn't doing what ...
putting in a date followed by a new line...
updating the record and going to the next one...
did you try them using
& chr(13) & chr(10)