Record Selectors on continuous form seem to select wrong record

G

Garyth

I have a continuous form which displays a list of invoices.

I am writing some code which will allow you to delete an invoice if it is
still 'to be processed' but not if it has already been processed.

I have put in code on the Before Del Confirm event to check if Me![Invoice#]
is equal to 'xxxx' (The invoice number if a invoice is still to be processed)
and allow the delete if that is the case and not allow the delete if it is
not the case.

My problem is that it seems to only allow the delete if the record below the
one selected is 'xxxx' - I did some testing and checked in the locals window
and when a certain record is selected the values for the variables are that
of the record listed below it !!! How can this be possible ? There is no
other code that I can find that messes with this form at all and I have tried
referring to a number of different controls linked to that record but every
time the local values seem to be for the record below the one selected (And
if it is the last record selected then the values are Null because it is
looking at the New Record line).

Any help would be greatly appreciated.
 
A

Allen Browne

Set the form's Record Selector property to Yes. You will now see an triangle
in the Record Selector at the left of your form, indicating which record is
actually the current one. Verify this is the record you expect.

If you are using Access 2007, and you have a control that is repeated on
every row of your form, you may find that Access runs your code before
moving the record selector to the record you intend to operate on.

If that does not apply, supply some more info please:

a) What version of Access is this?

b) And what service pack? For example, Help | About will show:
Access 2003 SP2 for Service Pack 2.
Check that you have the latest service pack for your version of Office:
http://support.microsoft.com/sp

c) What event are you using to run this code?
 
D

Dirk Goldgar

Garyth said:
I have a continuous form which displays a list of invoices.

I am writing some code which will allow you to delete an invoice if it is
still 'to be processed' but not if it has already been processed.

I have put in code on the Before Del Confirm event to check if
Me![Invoice#]
is equal to 'xxxx' (The invoice number if a invoice is still to be
processed)
and allow the delete if that is the case and not allow the delete if it is
not the case.

My problem is that it seems to only allow the delete if the record below
the
one selected is 'xxxx' - I did some testing and checked in the locals
window
and when a certain record is selected the values for the variables are
that
of the record listed below it !!! How can this be possible ? There is no
other code that I can find that messes with this form at all and I have
tried
referring to a number of different controls linked to that record but
every
time the local values seem to be for the record below the one selected
(And
if it is the last record selected then the values are Null because it is
looking at the New Record line).

Any help would be greatly appreciated.


In the BeforeDelConfirm event, the selected records have already been
provisionally deleted, and the current record is the next one *after* the
deleted records. If you choose to roll back the delete, the deleted records
will be restored.

Instead of the BeforeDelConfirm event to check the invoice#, use the Delete
event. In the delete event, the current record is the one being deleted.
 
G

Garyth

Thank you Dirk. This is exaclty the case. You are an Access guru ! I have
moved the code to the On Delete event and it now checks the correct record.

Allen, thanks for the attempt but please note that the record selectors were
enabled, and I mentioned in the first post that I was using the
BeforeDelConfirm event. In future I'll make sure to list the version of
access and try to state things more clearly.
 
G

GRIFFO

Allen is a legend, Dirk is also a legend.
Allen, your continuing commitment to this and other forums is an amazing
contribution to peoples work lives and knowledge.

Thanks to the both of you.
 
A

Allen Browne

Feedback appreciated, Griffo.

Yes: Dirk has also been a long-term contributor, always insightful.
 

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