on Focus event procedure not working (1 Viewer)

mcgraw

Registered User.
Local time
Today, 13:11
Joined
Nov 13, 2009
Messages
77
I have a form in Access 2007 with an "On Got Focus" procedure that is supposed to store the current value for a field.

Code:
Private Sub with_group_GotFocus()
Stop
Dim OldGroup As String
OldGroup = Me.with_group
End Sub

Then, the after update procedure is supposed to take that old field value and use it to populate a comment with both the old and new values.

Code:
Set rs = CurrentDb.OpenRecordset("CommentHistory")
With rs
    .AddNew
    !Issue_ID = Me.ID
    !ee = fOSUserName()
    !Comment_Date = Now()
    !Comment = "Group Assignment Changed from " & OldGroup & " to " & Me.with_group
    .Update
    
End With

For some reason, it isn't taking OldGroup and putting it into my comment. The new value is there, but it won't store the OldGroup?

How can I get the onFocus() event procedure to store the OldGroup, and have AfterUpdate() use that string for the comment?
 
I assume the Stop command is for debugging purposes, otherwise this will be the cause.

David
 
I assume the Stop command is for debugging purposes, otherwise this will be the cause.

David

Yes, I put the stop in to see if it was actually doing anything, and it appears to...though it skips the DIM OldGroup As String part.
 
Dim OldGroup As String

Put this statement outside of the Got_Focus Sub. It only exist there and is destroyed when the sub is finish executing.

Be sure to reset it after you have done updating your table.

JR
 
Where should I put it if not in the On Focus part? On form load?

And how would I destroy it, or does it go away when the form is closed?

Thanks!
 
Put it on the top of the Form Module like this:

Code:
Option Compare Database
Option Explicit
 
Dim OldGroupe As String

.....
...
the rest of your formCode

JR
 

Users who are viewing this thread

Back
Top Bottom