Detect and change when leave record

G

gg

Must be simple but can't see it. In a continuous form, I will call the
current record OldRecord. When the user moves to some other record on the
form I want to perform a check on OldRecord and insert a value in a field in
OldRecord that is dependent on the values of other fields in OldRecord. I
don't want popups and auto inserts while OldRecord has the focus. Thanks for
any help
 
S

Stefan Hoffmann

hi,
Must be simple but can't see it. In a continuous form, I will call the
current record OldRecord. When the user moves to some other record on the
form I want to perform a check on OldRecord and insert a value in a field in
OldRecord that is dependent on the values of other fields in OldRecord. I
don't want popups and auto inserts while OldRecord has the focus. Thanks for
any help
Use the form on current event, you need an unique key:


Private m_OldRecordID As Long

Private Sub Form_Current()

If m_OldRecordID <> -1 Then
CurrentDb.Execute "UPDATE Table " & _
"SET Field = Value " & _
"WHERE ID = " & m_OldRecordID, _
dbFailOnError
End If
m_OldRecordID = Me![ID]

End Sub

Private Sub Form_Load()

m_OldRecordID = -1

End Sub


mfG
--> stefan <--
 
G

gg

Stefan Hoffmann said:
hi,
Must be simple but can't see it. In a continuous form, I will call the
current record OldRecord. When the user moves to some other record on the
form I want to perform a check on OldRecord and insert a value in a field in
OldRecord that is dependent on the values of other fields in OldRecord. I
don't want popups and auto inserts while OldRecord has the focus. Thanks for
any help
Use the form on current event, you need an unique key:


Private m_OldRecordID As Long

Private Sub Form_Current()

If m_OldRecordID <> -1 Then
CurrentDb.Execute "UPDATE Table " & _
"SET Field = Value " & _
"WHERE ID = " & m_OldRecordID, _
dbFailOnError
End If
m_OldRecordID = Me![ID]

End Sub

Private Sub Form_Load()

m_OldRecordID = -1

End Sub


mfG
--> stefan <--
 
G

gg

Stefan Hoffmann said:
hi,
Must be simple but can't see it. In a continuous form, I will call the
current record OldRecord. When the user moves to some other record on the
form I want to perform a check on OldRecord and insert a value in a field in
OldRecord that is dependent on the values of other fields in OldRecord. I
don't want popups and auto inserts while OldRecord has the focus. Thanks for
any help
Use the form on current event, you need an unique key:


Private m_OldRecordID As Long

Private Sub Form_Current()

If m_OldRecordID <> -1 Then
CurrentDb.Execute "UPDATE Table " & _
"SET Field = Value " & _
"WHERE ID = " & m_OldRecordID, _
dbFailOnError
End If
m_OldRecordID = Me![ID]

End Sub

Private Sub Form_Load()

m_OldRecordID = -1

End Sub


mfG
--> stefan <--
Stefan
I "mis-clicked" and sent a blank-sorry
The code doesn't work. I get a message "Compile Error-variable not defined"
and
dbFailOnError highlighted. I should have said earlier that I am using
Access 2000 with Windows 2000. Can you also be more specific about "unique
key". For this learning experience, I have a simple Table called table1.
Three fields: ID (autoNumber), Alpha (text), Bravo (long Integer). Lets say
i want to update Bravo if Alpha="xyz".
 
Top