On Current event?

G

Guest

Please advice,
In order to detect a new record I using On current event:
Set Rs = CurrentDb.OpenRecordset("TBLtemp1", dbOpenDynaset)
If Me.NewRecord Then
....
In the form I need 1 field "WorkerID" can't be edit, I set Locked=True .The
other fields is editable.
So, when I click Navigation to add a new record the field "WorkerID" is empty.
How can I keep the old WorkerID as previous record?
Thank you for any advices.
MN
 
G

George Nicholson

Not 100% sure what you are asking but:

(In the OnCurrent event)
Static lngWorkerID as Long

If Me.NewRecord then
' Use the stored value for WorkerID
Me.WorkerID = lngWorkerID
Else
' Store the current WorkerID value
lngWorkerID = Me!WorkerID
End If

HTH,
 
G

Guest

Thanks a ton George!!!
It is working...but I got an err at:
lngWorkerID = Me!WorkerID <-- Runtime error 94--Invalid use of Null.
When I tried to click add more new record. Do you have any advice?
Regards.
MN
 
G

George Nicholson

Oops
I am assuming that you get that error when you try to add the 2nd of 2 new
records in a row (i.e., adding a new record from a new record).
If that isn't the circumstances under which you were getting the error, let
me know, since this probably won't help :)

1) At the top of your code module for the form (before the 1st function or
sub), add:
Private lngWorkerID as Long

2) Remove "Static lngWorkerID as Long" from the OnCurrent event. Leave the
rest as-is.

3) In the Form_AfterUpdate event, add:
lngWorkerID = Me!WorkerID
This should store the WorkerID value when you have just added (or updated) a
record.
Now, when you go to add a 2nd new record in a row, you shouldn't get the
"Improper use of Null" (I hope).

HTH,
 
G

Guest

Thanks George,
You are right, I got an error when I tried to add a 2nd or 3rd new record.
Here I am doing:
1) From the form Oncurrent event I keep:
Static LgWorkerID as Long
2) In the Form_AfterUpdate event I add:
LgWorkerID = Me!WorkerID
It is working perfectly event I add 10 more records ;-)

But right now in my table the data (WorkerID) not auto add-in yet!? I still
working on it.
Again thanks a lot--What helpful Access group are !!!
Regards,
MN
 

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