run code moving from record to another record

gearcam

Registered User.
Local time
Today, 21:05
Joined
Feb 7, 2008
Messages
30
HI how can i run some code when moving from one record to another

I know when the new record opens i can use current but whats the oppsite ie when leaving the record, not closing the form thats easy.

I might have 10 records from a search so as i scroll through them in a form i want to save some data on the record that is now not current.

Steve
 
You want to perform some action on the record that you're leaving?
 
Yes exactly
 
yes just amend a field content
So on opening the record the "current" sets a field to a value
Then on leving it sets to another value.

This will then be used to se if the form is open elswhere on a shared database
 
probablly i have quiete a good understanding of VB in access

Can you show me what you mean ?
 
From the RecordsetClone you can move to the previous record and do whatever you want to do there. You will still perform this function in the Current event of your form. E.g.:
Code:
dim rs as dao.recordset

set rs = me.recordsetclone

on error goto errorhandler
with rs
    .moveprevious
    .edit
    !FieldName = "new value"
    .update
end with

set rs = nothing

... your error handler here...
 
thanks i am going to giove this a try

So i add this into the form current code ?

I always get error 3021 "no record"
 
Last edited:
You will get that error on the first record (i.e. when you first open the form) and that's why I wrote in the code "... your error handler here... ", plus make sure your form's Record Source is a query, not a table.
 
That must be the problem then my form is linked to a table

It works if i change to .movefirst
so can i get the number of the record currentley showing on the screen and use that somehow ?
 
And have you changed it to a query?

No, it's not movefirst you want. I've already given you the code you need. Put error handling and it will be good to go.
 
no chaning to a query is a bit more complicated i think thi form has many many uses not sure if they will all work ill give it a go
 
If it was complicated I won't ask you to change it to a query. In any enironment, be it single-user or multi-user, it is advised to base your forms on queries.
 
Ok i have changed the data source for a new query that is linked to the table
but i still get error 3021
 
You're not fully doing what I advised. Let me see your entire Sub procedure.
 
Code:
Ok here is the full set up
The base table for all the data is called orders
I have a query with all fields called ordersfull (this is the new part)
I have a form called orders which is linked to the query ordersfull
 
this is the current section of the orders code
 
Private Sub Form_Current()
On Error GoTo Err_New_1_Click
 
Dim rs As dao.Recordset
Set rs = Me.RecordsetClone
With rs
.MovePrevious
.Edit
!who_formopen = "new value"
.update
End With
usercheck:
Set rs = Nothing
 
 
'all sorts of code here to do various calcs etc etc ....... 
 
 
Exit_New_1_Click:
Exit Sub
Err_New_1_Click:
temp = Err
If Err = 3021 Then
MsgBox [who_formopen] & " " & Err
Resume usercheck
End If
If Err = 2448 Then
MsgBox [who_formopen] & " has the form already open, opening read-only. " '& Error$
Resume Exit_New_1_Click
Else
MsgBox Err.Description
lockform
Resume Exit_New_1_Click
End If
 
End Sub
 
Last edited:
ok ill will buld a new test database from scratch and see what happens
thanks
Steve
 
Copy your db, delete irrelevant object from copy, enter test data and upload.
 

Users who are viewing this thread

Back
Top Bottom