Auto date changes on continues forms

G

Guest

I have a continous form that is used to lookup and change information. I am
trying to write the users ID and the current date. The functions ork on a
single form. Below is how I use the functions.

Private Sub Form_Load()
auditorwrt.Value = Auditortxt.Value
datewrt.Value = Datetxt.Value
End Sub

when this didnt work I tried the following function for the date:

Private Sub Form_BeforeUpdate(Cancel As Integer)
'auto date on update'
If Me.NewRecord Then
Me!datewrt.Value = Date

End If

'save changes dialog box'
Dim strMsg As String

strMsg = strMsg & "Click Yes to Save or No to Discard changes."
If MsgBox(strMsg, vbQuestion + vbYesNo, "Save Record?") = vbYes Then
'do nothing
Else
DoCmd.RunCommand acCmdUndo
End If
End Sub
 
G

Guest

I forgot to add that the form has a datetxt default value of =date() and the
auditortxt has a function to return the users network ID from Dev Ash
=fosuser()
 
P

Pat Hartman \(MVP\)

The two lines of code need to go into the Form's BeforeUpdate event.

Private Sub Form_BeforeUpdate(Cancel As Integer)
auditorwrt.Value = fosuser()
datewrt.Value = Date()
End Sub
 
G

Guest

Thank you. The big problem is that it only writes the first change that is
made to this continous form. Any additional changes are negated.

I am actually using =date() and =FOSuser() values on another text field
which is set equal on load.
Private Sub Form_Load()
auditorwrt.Value = Auditortxt.Value
datewrt.Value = Datetxt.Value
End Sub

I also tried to use the below on update as suggested but the same problem
occurs
Private Sub Form_BeforeUpdate(Cancel As Integer)
auditorwrt.Value = fosuser()
datewrt.Value = Date()
End Sub

--
Thanks,
Mauro


Pat Hartman (MVP) said:
The two lines of code need to go into the Form's BeforeUpdate event.

Private Sub Form_BeforeUpdate(Cancel As Integer)
auditorwrt.Value = fosuser()
datewrt.Value = Date()
End Sub
 
P

Pat Hartman \(MVP\)

Code in a FORM's BeforeUpdate event runs EVERY time a "dirty" record is
saved. So if you modify a record and save it and then modify it again, the
BeforeUpdate event runs again.

Code in a FORM's Load event runs only ONCE when the form was loaded and so
it will not run as each record is changed.

Turrisi said:
Thank you. The big problem is that it only writes the first change that is
made to this continous form. Any additional changes are negated.

I am actually using =date() and =FOSuser() values on another text field
which is set equal on load.
Private Sub Form_Load()
auditorwrt.Value = Auditortxt.Value
datewrt.Value = Datetxt.Value
End Sub

I also tried to use the below on update as suggested but the same problem
occurs
Private Sub Form_BeforeUpdate(Cancel As Integer)
auditorwrt.Value = fosuser()
datewrt.Value = Date()
End Sub
 
P

Pat Hartman \(MVP\)

The load event is not suitable for this purpose. It only runs when the form
is opened plus this code dirties the form even if the user doesn't change
anything. That means the date will be updated if a record is simply viewed
(but only for the first record since the code only runs once). The
BeforeUpdate event for the Form runs any time the record is dirtied, just
before Access saves it so your code doesn't dirty the record because it is
already dirty and in the process of being saved when you modify the auditor
and date values.
I prefer to use the Me. syntax when referring to form fields because that
syntax gives me intellisense.

Me.auditorwrt.Value = fosuser()

Me.datewrt.Value = Date() --- I would use Now() for this purpose since it
also includes time of day.

Turrisi said:
Thank you. The big problem is that it only writes the first change that is
made to this continous form. Any additional changes are negated.

I am actually using =date() and =FOSuser() values on another text field
which is set equal on load.
Private Sub Form_Load()
auditorwrt.Value = Auditortxt.Value
datewrt.Value = Datetxt.Value
End Sub

I also tried to use the below on update as suggested but the same problem
occurs
Private Sub Form_BeforeUpdate(Cancel As Integer)
auditorwrt.Value = fosuser()
datewrt.Value = Date()
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top