Hello
I have been hitting my head against the wall on this problem for a day
now. I have a simple table that stores cities, on of the fields on the
table is modified_by. I am trying to write the user who modifed the
table, in to the column modified_by. Code for getting the user that i
am using is environ("username"), it works fine; however for the life of
me i cannot figure out one which even to do this.
This is how the form is displayed
City:
modified_by:
What happens is that on Change event, i set focus to the modified_by
field and write the user name to it. Problem with that is that on
Change activates anytime i type one letter into the city field.
I also tried before update, change focus to modified_by field, however
it is as if the update never happens, when i try to advance the record
using navigation buttons.
I also tried dirty event; however, i just get run out of stack space
errors, any help or suggestions would be greatly appreicated.
THanks. 6 2339
Use the BeforeUpate event procedure of the *form* (not control) to assign
the value to the field.
--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.
<ph*******@hotmail.com> wrote in message
news:11*********************@r2g2000cwb.googlegrou ps.com... Hello
I have been hitting my head against the wall on this problem for a day now. I have a simple table that stores cities, on of the fields on the table is modified_by. I am trying to write the user who modifed the table, in to the column modified_by. Code for getting the user that i am using is environ("username"), it works fine; however for the life of me i cannot figure out one which even to do this.
This is how the form is displayed
City: modified_by:
What happens is that on Change event, i set focus to the modified_by field and write the user name to it. Problem with that is that on Change activates anytime i type one letter into the city field.
I also tried before update, change focus to modified_by field, however it is as if the update never happens, when i try to advance the record using navigation buttons.
I also tried dirty event; however, i just get run out of stack space errors, any help or suggestions would be greatly appreicated.
THanks.
Function getCurrentUser() As String
getCurrentUser = Environ("username")
End Function
Function runBeforeUpdate()
ModifiedBy.SetFocus
ModifiedBy.Text = getCurrentUser
End Function
Private Sub Form_BeforeUpdate(Cancel As Integer)
runBeforeUpdate
End Sub
This is my code here, i am using the beforeupdate on the form, the text
field in the form updates properly with the user who is modifing it,
but it the record does not advance when i use the record navigation
buttons to go to the next record. Thanks for your reply
Drop the ".Text" bit, and you don't need to SetFocus.
Unlike pure Visual Basic, where Text is the default property of a text box,
Access is a data-centric program, so Value is the default property of a text
box. The Text property applies only while a control has focus, and refers to
the text in the control that has not yet been accepted as its Value.
So all you need is:
Private Sub Form_BeforeUpdate(Cancel As Integer)
Me.ModifiedBy = Environ("username")
End Sub
--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.
<ph*******@hotmail.com> wrote in message
news:11**********************@p79g2000cwp.googlegr oups.com... Function getCurrentUser() As String getCurrentUser = Environ("username") End Function
Function runBeforeUpdate() ModifiedBy.SetFocus ModifiedBy.Text = getCurrentUser
End Function
Private Sub Form_BeforeUpdate(Cancel As Integer) runBeforeUpdate End Sub
This is my code here, i am using the beforeupdate on the form, the text field in the form updates properly with the user who is modifing it, but it the record does not advance when i use the record navigation buttons to go to the next record. Thanks for your reply
Thanks alot worked like a charm:) you ve been a great help.
One other question if i may, what is the event on Dirty, as i have been
reading the forums and i think i have come to an understanding that it
means that the form has had a change made to it?
The form's Dirty event fires when you *begin* to make a change to a record.
It does not exist in older versions of Access, and in some of the more
recent versions, the event does not fire if the record is dirtied
programmatically. It is therefore less than ideal for this kind of task.
The form's BeforeUpdate event fires at the last possible moment before the
record is saved. This event works consistently in all versions of Access. It
is most commonly used for record-level validation, but is also idea for this
kind of task. Particularly if you want to save the date and time of the last
edit, using the last possible moment before it is saved makes the best
sense.
It is possible to use the form events to write an audit trail of all
inserts, edits, and deletes. This involves using lots of the form events,
but if you ever need to do that, the details are here:
Audit Trail - Log changes at the record level
at: http://allenbrowne.com/AppAudit.html
--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.
<ph*******@hotmail.com> wrote in message
news:11**********************@f6g2000cwb.googlegro ups.com... Thanks alot worked like a charm:) you ve been a great help.
One other question if i may, what is the event on Dirty, as i have been reading the forums and i think i have come to an understanding that it means that the form has had a change made to it?
You got it right....
That is what it means.
And if you set it to false, that causes Access to save the record. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Raphael Gluck |
last post by:
Hi,
Is it possible for one to program one's pages as such that when a database
table is updated over the web, via a form, that an e-mail confirmation is
sent to a specified address, notifying...
|
by: Me |
last post by:
Hi...
A much lamented question, I guess..
I'm trying to create a simple audit trail.
log the changes to an SQL 2000 table, so that they are written into a
mirror table. The entire record, only...
|
by: Me |
last post by:
Hi...
A much lamented question, I guess..
I'm trying to create a simple audit trail.
log the changes to an SQL 2000 table, so that they are written into a
mirror table. The entire record, only...
|
by: Zlatko Matić |
last post by:
Hello.
I tried to implement audit trail, by making an audit trail table with the
following fileds:
TableName,FieldName,OldValue,NewValue,UpdateDate,type,UserName.
Triggers on each table were...
|
by: Jim M |
last post by:
I've been playing with Allen Browne's audit code and found it very
useful. I need to track record insertions, deletions, and edits for
several tables. I am planning to replace Access with Microsoft...
| |
by: Parag |
last post by:
Hello,
I have been assigned the task to design the audit trail for the ASP.NET web
application. I don't know what the best practices for such audit trails are.
Our application one dedicated user...
|
by: hary08 |
last post by:
im doing a database for Hospital Admission, I have a log in form which prompt user for a password. The source of log in is to look for the values in my Table tblEmployees and match user name and...
|
by: babamc4 |
last post by:
I have a main form (mainformlung) with 5 subforms (followupacute, followuplate, biochemresults, haemresults and pftresults). I have copied Allen Browne's Audit Trail code (thanks to Allen Browne)...
|
by: Emin |
last post by:
Dear Experts,
We need to design a database which has an audit trail for updates to a
certain set of tables. The two main approaches I've seen for this
include shadow tables (an extra table to...
|
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,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
| |
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: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |