• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 745
  • Last Modified:

Add Comments to a Memo field with date, time and username and append to the window

I am getting very close to finishing my database application right now.  

I have a Comments fields where I would like the users to add comments regarding their data load. I was thinking about either allowing Enter Key changed in properties for that field along with having a button to save a new comment.

I just do not understand how I could do the code to allow me to enter a new line in the field with the date and time stamp and user name plus the comment. I really do not want to do a subform at all.

Is this possible to do?
0
lauriecking0623
Asked:
lauriecking0623
  • 6
  • 6
1 Solution
 
Jim Dettman (Microsoft MVP/ EE MVE)PresidentCommented:
<< have a Comments fields where I would like the users to add comments regarding their data load. I was thinking about either allowing Enter Key changed in properties for that field along with having a button to save a new comment. >>

 If you want to control the comment field like that, I would display the memo field in a text control that is not enabled, then use a seperate unbound text control for the entry text itself (say txtCommentEntry) and have a button for "Save comment"

In the Button's OnClick Event do:

Me.<nameofmymemocontrol> = Me.<nameofmymemocontrol> & vbCRLF & Me.txtCommentEntry & vbCRLF & "Date/Time Posted: " & format$(Now(),"mm/dd/yy hh:nn:ss") & "  User: " & WhoAmi(True)

Note sure what your using for "usernames"; do you have a login in the app or do you want the newtowrk login name?  If the latter, I will paste the code for WhoAmI(), which is a procedure I use to fetch the network login name or station.

Jim.
0
 
als315Commented:
You can do it with code like this (Me.Comment - MEMO field, Me.NewComment - text field with comment to be added) :
If Len(Me.NewComment & "") > 0 Then
    Me.Comment = Me.Comment & vbCrLf & Date() & Me.NewComment
    Me.NewComment = Null
End If
You can also add other values like username etc.
0
 
lauriecking0623Author Commented:
@JDettman:

I was thinking of using a function like CurrentUsers().
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
Jim Dettman (Microsoft MVP/ EE MVE)PresidentCommented:
<<I was thinking of using a function like CurrentUsers(). >>

 CurrentUser(), unless your using User Level Security (which has been removed from the product with the ACE database format), will always return "Admin" as the user, so it's not much good<g>.

Paste the below into a module.  Declares go at the top of the module. Then call:

WhoAmI(True)

to get the username or

WhoAmI(False)

 To get the station name.

Jim.

Private Declare Function GetComputerNameA Lib "kernel32" (ByVal lpBuffer As String, nSize As Long) As Long
Private Declare Function GetUserNameA Lib "advapi32.dll" (ByVal lpBuffer As String, nSize As Long) As Long


Public Function WhoAmI(bReturnUserName As Boolean) As String

        ' Function returns either user name or computer name

        Dim strName As String * 255

10      If bReturnUserName = True Then
20        GetUserNameA strName, Len(strName)
30      Else
40        GetComputerNameA strName, Len(strName)
50      End If

60      WhoAmI = left$(strName, InStr(strName, vbNullChar) - 1)

End Function
0
 
lauriecking0623Author Commented:
@JDettman

I put in the code onto my form with the unbounded txtCommentsEntry so when I click on the save button, it says Compile Error: Method or data member not found. I am running Access 2010 64-bit version. I put in the PtrSafe that I need to run the code; however, I get this error. I am not sure why.

This is the code that I used:

Me.Comments = Me.Comments & vbCRLF & Me.txtCommentsEntry & vbCRLF & "Date/Time Posted:" & format$(Now(), "mm/dd/yy hh:nn:ss") & "User:" & WhoAmI(True)
0
 
Jim Dettman (Microsoft MVP/ EE MVE)PresidentCommented:
What's the name of your control displaying the contents of the memo field?  or what's the name of the memo field?

Jim.
0
 
lauriecking0623Author Commented:
It is named Comments.
0
 
Jim Dettman (Microsoft MVP/ EE MVE)PresidentCommented:
Try typing the line by hand:

 Me.

 and when you hit the dot, does intellisense list the control?

 and also, if you comment the statement out, does your app compile without error?

Jim.
0
 
lauriecking0623Author Commented:
Jim,

When I type the Me. it does not come up. Changed my code to Me!FRM_DataObjects!Comments that seems to work so far. I reran my code then it is throwing an error with Compile Error: Sub or Function not defined. and it is highlighting Me.txtCommentsEntry.

Thank you for help. I am not very good at programming and this is definitely a learning experience.

Laurie
0
 
Jim Dettman (Microsoft MVP/ EE MVE)PresidentCommented:
OK, where are you putting this code?  and where the two controls (Comment for the display of the memo field and txtCommentsEntry)?

And is this a single form, is it a main/subform combination?

Me.

 Refers to the current form (and can only be used in a code module for a form), so if your on a main form and referring to a control on a subform, the syntax needs to be a little different, hence the questions above.

Jim.
0
 
lauriecking0623Author Commented:
Jim,

I created a form called FRM_Comments and I have my main form with the comment box actually on it called FRM_DataObjects. I put a button on my main form that opens up the FRM_Comments with an unbound text field called txtCommentsEntry. So I created a module called basWhoAmI with the information that you provided. I put the other line that I am having an error with on the command button called cmdAddNewComment.

Do I make sense?

Laurie
0
 
Jim Dettman (Microsoft MVP/ EE MVE)PresidentCommented:
OK, so your comment entry is basically on a popup and all it has is the comment entry?  If yes, then the code needs to refer to your main form like this:

Forms![FRM_DataObjects]![Comments] = Forms![FRM_DataObjects]![Comments] & vbCRLF & Me.txtCommentsEntry & vbCRLF & "Date/Time Posted:" & format$(Now(), "mm/dd/yy hh:nn:ss") & "User:" & WhoAmI(True)

 And you should be good!

 Me is a short hand in code for referring to the current form, so you can't use it to refer to the control that's on your first form.

  And for future reference, if you are working with an actual main form with a subform control, then from the main form, you refer to subform controls like this:

 Forms![<mainformname>]![<subformcontrolname>].Form![<controlnameonthesubform>]

replacing everything (and including) in the < >'s.   Also one gotcha there is that it's the name of the subform control itself that you use, not the actual name of the subform that you see in the database container.   They may be the same, but they don't have to be.


 and if writting it in code that sits in the main form, then you can shorten it to:

 Me![<subformcontrolname>].Form![<controlnameonthesubform>]

and if your writing code that is in the subform, you can refer to the parent (main) form with:

 Me.Parent

HTH,
Jim.
0
 
lauriecking0623Author Commented:
Jim was an excellent with his help. It works great now. He even explained to me how to do the comments addition about how VBA works with the forms. Thank you so very much.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 6
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now