DataBase - insert date and time into memo field

Asked By mboren
28-Jan-10 04:17 PM
Using access 2003

Have a status form when staff enters their progress into a memo field

I need the user to be able to enter the date and time of his entry

The end result will be a short cut the will insure the infomation, I just
cannot figure out the code for either a macro or a module that will do it.
VBA
(1)
GetUserNameA
(1)
FOSUserName
(1)
ApiGetUserName
(1)
VbCrLf
(1)
StrUserName
(1)
NoteDate
(1)
TxtMemofield
(1)
  John W. Vinson replied to mboren
28-Jan-10 04:50 PM
If you are storing multiple dates and multiple progress steps in a single memo
field... you are sowing trouble for yourself. It will be very difficult or
impossible to search this big amorphous blob of text with some embedded dates.

I would strongly suggest that you instead create a Table related one-to-many
to this table (whatever it is); it should have a foreign key ID field for the
link, a NoteDate field with a default value of Now() to trap the time that an
entry is made, and a Text or Memo field into which the staff member will enter
their progress.

If you really want one big (essentially unsearchable) memo field you can use
some VBA code to enter the date and time; you will need to tell us what form
event would be appropriate: do you want the field timestamped when the user
opens the form, or moves to a particular record, or sets focus to the notes
textbox, or clicks a button, or what?
--

John W. Vinson [MVP]
  mboren via AccessMonster.com replied to John W. Vinson
29-Jan-10 09:10 AM
Wow, thanks for the response; yeah, know about the lack of search capability,
but this is more like a diary which people enther there  information  to the
bottom of the field; brilliant people but people who cannot seem to remember
to type in the date.

In my ideal world the user will enter a shortcut (ctrl y would be fine) and
wherever the curser is, the date (and username, i did not mention that in the
first message) will be inserted.  Hopefully they will insert it at the left
of a blank line and only use it once, but that will be there problem.

Would love to see what this looks like in VBA, its frustrated me.

thanks again

michael







--
Message posted via http://www.accessmonster.com
  John W. Vinson replied to mboren via AccessMonster.com
29-Jan-10 12:55 PM
My suggested table would automatically fill in the date AND let them enter
their diary. You can display it on a Continuous Form so you can see past
entries easily.


If you insist. Put a Command Button cmdDiary on the form with a Caption of


This will display Diary with the y underlined, and typing Alt-Y on the
keyboard will click the button. In its code put

Private Sub cmdDiary_Click()
Dim Username as String
Username = fOSUserName()
Me!txtMemofield.SetFocus
Me!txtMemofield = Me!txtMemofield & vbCrLf & Date & " " & Username
Me!txtMemofield.SelStart = Len(Me!txtMemofield)
End Sub
'******************** Code Start **************************
' This code was originally written by Dev Ashish.
' It is not to be altered or distributed,
' except as part of an application.
' You are free to use it in any application,
' provided the copyright notice is left unchanged.
'
' Code Courtesy of
' Dev Ashish
'
Private Declare Function apiGetUserName Lib "advapi32.dll" Alias _

Function fOSUserName() As String
' Returns the network login name
Dim lngLen As Long, lngX As Long
Dim strUserName As String
strUserName = String$(254, 0)
lngLen = 255
lngX = apiGetUserName(strUserName, lngLen)
If ( lngX > 0 ) Then
fOSUserName = Left$(strUserName, lngLen - 1)
Else
fOSUserName = vbNullString
End If
End Function
'******************** Code End **************************

The fOSUserName code is from http://mvps.org/access/api/api0008.htm (and there
are tons more useful code on that site).
--

John W. Vinson [MVP]
  Ron2006 replied to mboren via AccessMonster.com
30-Jan-10 12:49 PM
What we have done to facilitate this type of logging is the following:

1) not allow direct logging into the memo field.
2) User double clicks on the field in order to update. When they do
this it opens a new form which shows the current content of the memo
field and another txtbox that they can enter new information into.
3) button on that form that says to add new comments to existing
information.
4) when button is pressed then construct the update to be
oldcomentfield = oldcommentfield & now() & " " &
newtoaddcommentsfield
OR
oldcommentfield = now() & " " & newtoaddcommentsfield & " " &
oldcommentfield
5) form also contains button to exit without any updating.

Ron
  mboren via AccessMonster.com replied to John W. Vinson
29-Jan-10 03:55 PM
works great, it is a work of sheer genius, putting code in a button  and
adding a shortcut to it, amazing.
thank you all very much
i hope you realize you have adopted me
michael




--
Message posted via http://www.accessmonster.com
  John W. Vinson replied to mboren via AccessMonster.com
29-Jan-10 06:28 PM
LOL!!!


--

John W. Vinson [MVP]
Create New Account
help
FROM DUAL;" Can I do something similar in MS Access? Access Queries Discussions Oracle (1) VBA (1) VB (1) GetNetworkUserName (1) GetUserNameA (1) FOSUserName (1) ApiGetUserName (1) Database (1) The VBA function CurrentUser() returns the name of the user logged into the database. (Note that if that i have been using that i found online. ' Code Courtesy of ' Dev Ashish ' Function fOSUserName() As String ' Returns the network login name Dim lngLen As Long, lngX As Long Dim String strUserName = String$(254, 0) lngLen = 255 lngX = apiGetUserName(strUserName, lngLen) If (lngX > 0) Then fOSUserName = Left$(strUserName, lngLen - 1) Else fOSUserName = vbNullString End If End Function you also need to declare this first, on top of
get the network login name: Private Declare Function apiGetUserName Lib "advapi32.dll" Alias _ Function fOSUserName() As String ' Returns the network login name Dim lngLen As Long, lngX As Long Dim String strUserName = String$(254, 0) lngLen = 255 lngX = apiGetUserName(strUserName, lngLen) If lngX <> 0 Then fOSUserName = Left$(strUserName, lngLen - 1) Else fOSUserName = vbNullString End If End Function This code is available widely from the internet and I such that I could not examine the values of variables there. It seems the statement "fOSUserName = Left$(strUserName, lngLen - 1)" is causing trouble. If I comment out that statement, I do I have missed? thanks. Access Discussions Access 2007 (1) Access 2003 (1) Windows 7 (1) VBA (1) XP (1) GetUserNameA (1) FOSUserName (1) ApiGetUserName (1) I just copied your code into a new database in Access 2007 now, the Compile Error pops up at the moment when Stepping Into the line "Function fOSUserName() As String"; while at the same time the debugger would highlight "LEFT$" several lines down
User Name into Access 2003 table DataBase It seems like there would be an easy VBA call to do this, but I have not found it yet. . . I am trying to populate the user name in a transactional database. Is there some simple (or not simple) VBA code that is out there to accomplish this? Perhaps something internal to Access 2003? Access DAO Discussions Windows XP (1) Active Directory (1) Access 2003 (1) Excel (1) Word (1) VBA (1) GetUserNameA (1) FOSUserName (1) Take a look at www.mvps.org / access and browse the API section (and www.tristatemachine.com -Thomas Edison (1847-1931) hi, Option Compare Database Option Explicit Declare Function GetUserNameA _ Lib "advapi32.dll" (ByVal lpBuffer As String, nSize As Long) As Long Public Function As Long Dim size As Long buffer = String(BUFFER_SIZE + 1, 0) size = BUFFER_SIZE + 1 result = GetUserNameA(buffer, size) If result <> 0 Then GetUserName = Left$(buffer, size - 1) End If End Function reason. If Len(gWindowsUserId) = 0 Then setWindowsUserId getWindowsUserId = gWindowsUserId End Function Sub setWindowsUserId() gWindowsUserId = Left(fOSUserName, Len(fOSUserName())) End Sub setWindowsUserId has other code in it that warrants it being its
does not need to be secured. thanks much Access Modules DAO Discussions SQL Server (1) VBA (1) GetUserNameA (1) FOSUserName (1) GetUserName (1) Database (1) CurrentUser (1) DougSteele (1) http: / / www.mvps.org / access / api a module anywhere? Then create a query field with Criteria = GetUserName? Or a field UserID:GetUserNameA (syntax?) See http: / / www.mvps.org / access / api / api0008.htm for VBA code to get the Windows logon id. John Spencer Access MVP 2002-2005, 2007-2009 The Hilltop Institute University of Maryland Baltimore County Copy the module into a VBA module. Then you can use fOSUserName() to return the current windows user name. You would NOT use that as criteria, but on a form where the control was bound to the relevant field in your table. = fOSUSerName Or you could use the Before Update event of the form to populate the field