473,394 Members | 1,694 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Catch the current date, time and login name when record is being edited.

111 100+
I have a qry bound form showing the search results based on the user entered criteria. There is a button called Edit on that form. The form is locked initally to stop user to edit any record accidentally.
When user clicks on edit, all the controls go unlocked and user can edit the record. There three fields on the form showing who entered data (ModeUserId, ModeDate, ModeTime). I want these fields to change there value accordingly(meaning it should show current date, time and user logged in)
How do I do that?
Dec 16 '09 #1
12 3146
missinglinq
3,532 Expert 2GB
The code would be:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_BeforeUpdate(Cancel As Integer)
  2.   Me.ModeDate = Date
  3.   Me.ModeTime = Time 
  4.   Me.ModeUserId = CurrentUserID
  5. End Sub
The only question, though, is where are you going to get the value for CurrentUserID?

Do you want the Windows User ID or do your users have to log into the database, or what?

What version of Access are you running/going to be running this on?

Linq ;0)>
Dec 16 '09 #2
AccessBeetle
111 100+
It is custon login interface so I will be catching that using dlookup function.
Hey but it did not change the values like it should have.
Access 2003, SP 2
Dec 16 '09 #3
AccessBeetle
111 100+
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_BeforeUpdate(Cancel As Integer)
  2. 'Provide the user with the option to save/undo
  3. 'changes made to the record in the form
  4.  
  5.     If MsgBox("Changes have been made to this record." _
  6.         & vbCrLf & vbCrLf & "Do you want to save these changes?" _
  7.         , vbYesNo, "Changes Made...") = vbYes Then
  8.             DoCmd.Save
  9.             Me.ModDate = Date
  10.   Me.ModTime = Time
  11.   Me.ModUserID = DLookup("[Username]", "RadioLog_tblValUsers", "[UserName]= '" & [Forms]![frmLogin]![txtUsername] & "'")
  12.  
  13.         Else
  14.             DoCmd.RunCommand acCmdUndo
  15.     End If
  16.  
  17.  
  18. End Sub
OK I changed the code like above. Now it shows correct ModUserId but date is not being edited at all and time is wrong. I mean it does not show the current time.It shows some garbage time. What is going on wrong here?
Dec 16 '09 #4
AccessBeetle
111 100+
ok here is the solution.
1. Now() funtion with input mask works better.
2. Me.Refresh refreshes form with updated data.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_AfterUpdate()
  2. Me.Refresh
  3. End Sub
  4.  
  5. Private Sub Form_BeforeUpdate(Cancel As Integer)
  6. 'Provide the user with the option to save/undo
  7. 'changes made to the record in the form
  8.  
  9.     If MsgBox("Changes have been made to this record." _
  10.         & vbCrLf & vbCrLf & "Do you want to save these changes?" _
  11.         , vbYesNo, "Changes Made...") = vbYes Then
  12.             DoCmd.Save
  13.             Me.ModDate = Now()
  14.             Me.ModTime = Now()
  15.             Me.ModUserID = DLookup("[Username]", "RadioLog_tblValUsers", "[UserName]= '" & [Forms]![frmLogin]![txtUsername] & "'")
  16.  
  17.         Else
  18.             DoCmd.RunCommand acCmdUndo
  19.     End If
  20.  
  21.  
  22. End Sub
Dec 16 '09 #5
missinglinq
3,532 Expert 2GB
If Date() and Time() didn't work for you it means that you've got a missing reference library. Since these are very basic functions in Access, and share the library with many others, you should keep this in mind if you start having problems with other functions failing.

Be aware that while you're seeing the date in ModDate and the time in ModTime, when looking at your form, in actuality both of these fields, in the underlying table, are going to show both date and time, which is what Now() returns. In other words, the data in ModDate and ModTime will always be identical, which violates the rules!

Also, DoCmd.Save saves design changes made to the form, it does not save changes made to the record! To save the record you need to use something like

DoCmd.RunCommand acCmdSaveRecord

or

If Me.Dirty Then Me.Dirty = False

Linq ;0)>
Dec 16 '09 #6
AccessBeetle
111 100+
Thanks for heads up!! I really appreciate your help. Thanks for telling otherwise I would have keep it that way.
If Date() and Time() didn't work for you it means that you've got a missing reference library.
How to fix it?
Dec 17 '09 #7
missinglinq
3,532 Expert 2GB
You’ll have to actually have the functions used in code, i.e. set

Me.ModDate = Date()

like you had it when it was misbehaving, then run it (to be sure it’s still acting up and wasn’t just a temorary Access burp; Access does that sometimes) then use Doug Steele’s detailed instructions on how to troubleshoot the problem:

http://www.accessmvp.com/DJSteele/Ac...nceErrors.html

Linq ;0)>
Dec 17 '09 #8
AccessBeetle
111 100+
Thanks. I did write the function in code but as you have wrote it eliminnates the brackets. it only takes something like this.
Expand|Select|Wrap|Line Numbers
  1.  If MsgBox("Changes have been made to this record." & vbCrLf & vbCrLf & "Do you want to save these changes?", vbYesNo, "Changes Made...") = vbYes Then
  2.             DoCmd.RunCommand acCmdSaveRecord
  3.             Me.Text61 = Date
  4.             Me.Text63 = Time
  5.             Me.ModUserID = DLookup("[Username]", "RadioLog_tblValUsers", "[UserName]= '" & [Forms]![frmLogin]![txtUsername] & "'")
  6.  
  7.         Else
  8.             DoCmd.RunCommand acCmdUndo
  9.     End If           
but the link you have given is for Access 2000 and Access 2002. I am using Access 2003 with SP 2. Let me know if you know the specific link for it.

Also, when I wrote the aboce code it give me runtime error 2115. Any solution for that?
THanks for all your help
Dec 17 '09 #9
Megalog
378 Expert 256MB
I'd remove the code to save the record.. since this is a BeforeUpdate event. Not sure why your date/time fields are getting funky though. Make sure that the fields in your table are not named "Date" or "Time", they're reserved words. And make sure any controls on your form are also not named that.
Dec 17 '09 #10
AccessBeetle
111 100+
No I don't have any control named like "Date" or "Time". Also, my field names are ADate and ATime. When I use the code in Post #9, it gives me Runtime error MS Access can't find the field 'Time' referred to in your expression. The ADate field is updated with Me.Text61 = Date, but not the ATime field.

Also, I want to tell user that the record has been updated, that is why I put that code there? Is there anywhere else I can pput it which notifies and gives user an option if he wants to go ahead with the editing he made.
Dec 18 '09 #11
missinglinq
3,532 Expert 2GB
What event do you that code in? It needs to be in the Form_BeforeUpdate event, and as Megalog said, you really don't need the line to save the record. I think moving it to this event will probably solve the 2115 error, as well.

And Doug's advice on Reference troubleshooting applies to version 2003 as well. Not recognizing the Time() function is really indicative of a missing reference, as it is a standard Access function.

Linq ;0)>
Dec 18 '09 #12
Megalog
378 Expert 256MB
I would think having it save the record while in a BeforeUpdate event would cause the error, or send it into a loop of some sort.

I would use the code in post #5, just remove any line that saves the record.
Dec 18 '09 #13

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Galina | last post by:
Hello I have an application in MS Access 2000. I have a form, which includes a subform. The subform is based on a table, but locked for any editing. There is Edit button. When clicked, it starts a...
3
by: tsteinke | last post by:
What is the syntax to refer to your current row in an SQL statement? I am using the "Lookup Wizard" to build a query in a table. How do you refer to the Current Row For instance I have a Table...
11
by: Ken Varn | last post by:
I want to be able to determine my current line, file, and function in my C# application. I know that C++ has the __LINE__, __FUNCTION__, and __FILE___ macros for getting this, but I cannot find a...
6
by: ECathell | last post by:
I am having a problem with my try..catch blocks... I push a button on my form. using SQLDMO I verify the status of the server. If it is off I turn it on. I then run a query that requires a...
14
by: Tina | last post by:
My employer tracks productivity/performance of clinicians (how much they bill) each week, its averages for the month, and the 6 months. These averages are compared to their expected productivity....
5
by: christianlott1 | last post by:
I admit my form is pretty complex and may need a total overhaul - I have two subforms synchronized on a form through an unbound text box. When I enter a new record in the second subform it used...
4
by: SilentThunderer | last post by:
Hey folks, Let me start out by letting you know what I'm working with. I'm building an application in VB 2005 that is basically a userform that employees can use to "Clock in". The form...
23
by: dhtmlkitchen | last post by:
JSON We all know what it is. In ECMAScript 4, there's a JSON proposal: Object.prototype.toJSONString String.prototype.parseJSON The current proposal, String.prototype.parseJSON, returns...
1
by: THEAF | last post by:
i'm trying to create a reminder form, when i add a new reminder its ok but when i try to delete a reminder then i get No Current Record problem. Form Load Private Sub Form_Load() Dim s() As...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.