Solved Add date and Time at the start of Memo field (1 Viewer)

Russty

New member
Local time
Tomorrow, 07:50
Joined
Dec 7, 2021
Messages
3
Hi
There was a post about this back in 2014 which I tried to make work, but am stuck on one thing.
I have a memo field in the form.
When the user tabs into or clicks into this field the current date and time is placed at the top of the memo field, with all the existing memo field moved down with one additional space under the date line. This is where I want the cursor to be. Code below does most of it, but the cursor will only position at the end of the date line.

Private Sub NoteT_Enter()
Dim DateLength As Integer

DateLength = Len(Format(Now(), " d mmm yyyy hh:nn"))
Me.NoteT = Format(Now(), " d mmm yyyy hh:nn") & vbNewLine & vbNewLine & Me.NoteT
Me.NoteT.SetFocus
Me.NoteT.SelStart = Me.NoteT.SelStart = DateLength & vbNewLine

End Sub

Thanks
Ken.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 04:50
Joined
May 7, 2009
Messages
19,169
Private Sub NoteT_Enter()
Dim DateLength As Integer
Dim Dte As String
Dte = Format(Now(), " d mmm yyyy hh:nn") & " "
DateLength = Len(Dte)
Me.NoteT = Dte & vbNewLine & vbNewLine & Me.NoteT
Me.NoteT.SetFocus
Me.NoteT.SelStart = DateLength
Me.NoteT.SelLength=0

End Sub
 

theDBguy

I’m here to help
Staff member
Local time
Today, 13:50
Joined
Oct 29, 2018
Messages
21,358
Have you tried?

Me.NoteT.SelStart=DateLength+2
 

plog

Banishment Pending
Local time
Today, 15:50
Joined
May 11, 2011
Messages
11,611
This sounds like an issue that needn't exist. I don't think you've set up your tables properly to store your data.

You are cramming a ton of information into that one Memo field that should be in its own table in seperate fields. When someone adds a new Memo to that memo field you are essentially adding a new record: MemoDate and MemoText. Worse still, all previous MemoDate/MemoText "records" are in that one field as well just getting pushed down.

I think you need a new table for this:

tblMemo
MemoID, autonumber, primary key
MemoFK, number, foreign key back to the table your current Memo field is in
MemoDate, date, date of this specific memo
MemoText, text, text of this one memo

With that table you can now add however many memos you need to your existing record in the table you currently have. No VBA tricks necessary and better yet, its searchable and orderable by date.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 04:50
Joined
May 7, 2009
Messages
19,169
try removing your code from the Enter event of NoteT textbox.
then put these codes on your form:

Code:
Option Compare Database
Option Explicit

'arnelgp
Dim handled As Boolean

'arnelgp
Private Sub NoteT_Click()
Dim DateLength As Integer
Dim Dte As String
If Not handled Then
    Dte = Format(Now(), " d mmm yyyy hh:nn") & " "
    DateLength = Len(Dte)
    Me.NoteT = Dte & vbNewLine & vbNewLine & Me.NoteT.Text & ""
    Me.NoteT.SelStart = DateLength
    handled = True
End If
End Sub

'arnelgp
Private Sub NoteT_LostFocus()
handled = False
End Sub
 
Last edited:

Russty

New member
Local time
Tomorrow, 07:50
Joined
Dec 7, 2021
Messages
3
Hi
Thanks to Arnelgp and theDbGuy.
A combination of both makes it work well.
The line "Me.NoteT.SelStart=DateLength+2" needs to be there to force the return for the cursor. The rest works excellent.
 

MarkK

bit cruncher
Local time
Today, 13:50
Joined
Mar 17, 2004
Messages
8,178
OP: I would like to hang myself.
arnel: Tie the knot like this...
dbGuy: Put it around your neck...
plog: Noooo, hanging yourself is a mistake! Try this instead...
arnel: Step up on the milk crate, and...
OP: Thanks arnel and dbGuy, this will totally work. *kicks milk crate from under feet*

Typical day at AWF.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 16:50
Joined
Feb 19, 2002
Messages
42,976
@Russty
That makes three of us who strongly disagree with your "solution". arnelgp took your request literally and so did thedbguy and never looked beyond it. You asked how to load your gun and they thoughtlessly replied with code and directions even though I know that they both know this is probably a bad idea and using the table solution will not only require no code (as your request is stated) but it is far more flexible for future use.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 13:50
Joined
Oct 29, 2018
Messages
21,358
OP: I would like to hang myself.
arnel: Tie the knot like this...
dbGuy: Put it around your neck...
plog: Noooo, hanging yourself is a mistake! Try this instead...
arnel: Step up on the milk crate, and...
OP: Thanks arnel and dbGuy, this will totally work. *kicks milk crate from under feet*

Typical day at AWF.
@Russty
That makes three of us who strongly disagree with your "solution". arnelgp took your request literally and so did thedbguy and never looked beyond it. You asked how to load your gun and they thoughtlessly replied with code and directions even though I know that they both know this is probably a bad idea and using the table solution will not only require no code (as your request is stated) but it is far more flexible for future use.
I am merely trying to help with the current situation. I cannot presume to know the whole situation. I try to offer suggestions without criticizing other suggestions that may be different than mine. Cheers!
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 04:50
Joined
May 7, 2009
Messages
19,169
I am merely trying to help with the current situation. I cannot presume to know the whole situation. I try to offer suggestions without criticizing other suggestions that may be different than mine. Cheers!
all i can say is that if they have complain, go to the police and complain there.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 16:50
Joined
Feb 19, 2002
Messages
42,976
@theDBguy I don't want to get into a fight with you and @arnelgp over this. I respect your contributions too much. But, honestly, do you really think this is a good idea? Opening up a memo field to a specific point and just letting the user type, or delete, whatever? I don't object to providing code to do something wrong. I generally refuse to do it but if you want to, that's fine. But some things are so dangerous, they just shouldn't be enabled. This is one of those things. The table solution required no code if you don't log the userID and only one line of code if you do. Beyond that, Access handles everything. You just set the property on the form to not allow updates or deletes. Just allow adds. It really doesn't get much easier to explain to a novice especially if you take the time to make him understand why his "solution" is too dangerous to be used
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 16:50
Joined
Feb 19, 2002
Messages
42,976
Does that mean that there's now four of us who think this "solution" is dangerous?
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 04:50
Joined
May 7, 2009
Messages
19,169
Does that mean that there's now four of us who think this "solution" is dangerous?
it does not matter what you think, it's what the OP thinks and he marked this as Solved.
now go to the Supreme Court to overturn this "solved" thread.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 16:50
Joined
Feb 19, 2002
Messages
42,976
The OP has made three posts in the year and a half that he's been a member and two of them were in this thread. He's long gone. It will be a while before he figures out what a dangerous solution he adopted. It's the others who come later that matter.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 04:50
Joined
May 7, 2009
Messages
19,169
It will be a while before he figures out what a dangerous solution he adopted
no! he has the solution since 2014. so stop dreaming of how this thread "ought" to have turned out. it will never happen.
 

MarkK

bit cruncher
Local time
Today, 13:50
Joined
Mar 17, 2004
Messages
8,178
@arnelgp, it harms AWF if your OP marks your bad solution solved. People who don't know better assume a solved solution is a good one. Please stop doing that kind of damage around here. Thanks,
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 04:50
Joined
May 7, 2009
Messages
19,169
it harms AWF if your OP marks your bad solution solved
what harm does it does and what is bad?
are there Rules on this Forum that you can cite?
Please stop doing that kind of damage around here.
it's your comment that is damaging this site.
 

Users who are viewing this thread

Top Bottom