Function runs twice

  • Thread starter Thread starter BobG
  • Start date Start date
B

BobG

After a form record has been "Verified" as correct, I created a
DoDairy function to create a log entry in another subform on that form.

When someone edits a verified record, I create a new record in the
Diary subform to track the Field, DateofEdit, User, and any
Comments about the change in the Diary subform.

One field (Speed) has this in the AfterUpdate event.
=DoDiary([Screen].[ActiveControl].[Name])

Public Sub DoDiary(CallingControl As String) ' *** DO DIARY ****
Dim GetComments As String
If Not IsNull(Forms![frmMachineAdjustments]![VerifyDate]) Then
Forms![frmMachineAdjustments]![frmMachineAdjustmentsDiary].SetFocus
DoCmd.GoToRecord , , acNewRec
Forms![frmMachAdj]![frmMachAdjDiary].Form![Field] = CallingControl
Forms![frmMachAdj]![frmMachAdjDiary].Form![DateofEdit] = Now()
Forms![frmMachAdj]![frmMachAdjDiary].Form![User] = CurrentUser
Prompt = "Updating " & CallingControl & vbcrlf & "Please Enter
Comments"
Title = "Editing A Verified Record"
GetComments = InputBox(Prompt, Title)
Forms![frmMachineAdj]![frmMachAdjDiary].Form![Comments] =
GetComments
DoCmd.GoToControl CallingControl
End If
End Sub

My problem is that the whole function runs twice!
One record fills out properly, but it repeats one more time.
* If I remove the InputBox portion of the code, the remaining
fields are updated only once.

What's wrong with my InputBox code?

Any assistance would be appreciated.
 
I would hazard a guess that the InputBox removes enough of the focus to
cause Access to try and save the forms data. Of course you then alter the
comments thus dirtying the form again and then there is the second coming.

Apart from that, it is refreshing to see someone still using the expression
service and the real and original grunt behind the unique EventProperties in
Access.

hth
peter walker
 
Peter,
Well, it's a real mystery.
I moved the function into the AfterUpdate event in the form module
instead of calling it from the AfterUpdate property line. That worked.
DoDiary "Speed"
Then I tried = DoDiary Screen.ActiveControl.Name and that worked.
So, I put back into a function call in the AfterUpdate property box =
DoDiary(Screen.ActiveControl.Name)
and that worked, where it wouldn't before!
I have no idea what the problem was. All my code is exactly the same,
but now I get just the one entry in the Diary.
Apart from that, it is refreshing to see someone still using the
expression
service and the real and original grunt behind the unique EventProperties
in
Access.
Not sure what that means, but it sounds like a compliment!
Thanks,
BobG

peter walker said:
I would hazard a guess that the InputBox removes enough of the focus to
cause Access to try and save the forms data. Of course you then alter the
comments thus dirtying the form again and then there is the second coming.

Apart from that, it is refreshing to see someone still using the
expression
service and the real and original grunt behind the unique EventProperties
in
Access.

hth
peter walker


BobG said:
After a form record has been "Verified" as correct, I created a
DoDairy function to create a log entry in another subform on that form.

When someone edits a verified record, I create a new record in the
Diary subform to track the Field, DateofEdit, User, and any
Comments about the change in the Diary subform.

One field (Speed) has this in the AfterUpdate event.
=DoDiary([Screen].[ActiveControl].[Name])

Public Sub DoDiary(CallingControl As String) ' *** DO DIARY ****
Dim GetComments As String
If Not IsNull(Forms![frmMachineAdjustments]![VerifyDate]) Then
Forms![frmMachineAdjustments]![frmMachineAdjustmentsDiary].SetFocus
DoCmd.GoToRecord , , acNewRec
Forms![frmMachAdj]![frmMachAdjDiary].Form![Field] =
CallingControl
Forms![frmMachAdj]![frmMachAdjDiary].Form![DateofEdit] = Now()
Forms![frmMachAdj]![frmMachAdjDiary].Form![User] = CurrentUser
Prompt = "Updating " & CallingControl & vbcrlf & "Please Enter
Comments"
Title = "Editing A Verified Record"
GetComments = InputBox(Prompt, Title)
Forms![frmMachineAdj]![frmMachAdjDiary].Form![Comments] =
GetComments
DoCmd.GoToControl CallingControl
End If
End Sub

My problem is that the whole function runs twice!
One record fills out properly, but it repeats one more time.
* If I remove the InputBox portion of the code, the remaining
fields are updated only once.

What's wrong with my InputBox code?

Any assistance would be appreciated.
 
Back
Top