Next Record Event Procedures - Prob v easy...

Joined
Mar 23, 2004
Messages
241
Hi guys.

These are probably very simple questions, but ones I can't seem to track down the answers to in the help files or my Access book... I'm probably being very thick:

1. Where can I put a bit of code in when a user tries to move between records on a form?
Is there a MoveRecord event or something? I want to only allow the users to leave the current record when they've fulfilled certain criteria.
(To explain further, I want certain fields completed, then a button clicked which assigns a policy number to the record. I don't want them to leave the newly created record until all this has been done. Because of the button click, I'm not sure the .dirty property will work, and I can't use the built-in validation)

2. Is there any way to disable the mouse wheel navigation?
I want to only allow navigation via buttons I've created (there's code attached to them, you see). I've disabled all the things I could find, but the mouse wheel still allows navigation.

Any help would be really appreciated...!
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
To answer question 1, use the BeforeUpdate event on the form (which fires when you try to leave the record and move elsewhere).
Along the lines of...
Test for values in certain fields. If blank, cancel, display a message, and go to the field.
To trigger the button click code, you can add a line like MyButtonName_Click to the AfterUpdate code. That way, the field gets filled in even if the user doesn't click the button (of course you'll need to check that the Policy No field is blank before trying to overwrite it).

Question 2 -- well, that's a good question! :biggrin:

Denis
 
Upvote 0
Hi Denis,

Thanks for your post...

I tried the BeforeUpdate event, and that didn't seem to do the trick. I put a simple Beep in the code, but nothing happened. Should that have worked?

Cheers,
CSBBB.
 
Upvote 0
I did a dummy run and this construct works with both text and number fields. In the BeforeUpdate event of the Form, put this for each field that you want to validate:
Code:
If IsNull([txtName]) Then
  MsgBox "You must have a value in the Name field"
  Cancel = True
  [txtName].SetFocus
End If
Change field names to suit

Denis
 
Upvote 0
Hi again.

Thanks for the post, Denis.

The code you provided still isn't working. I can still enter half the required data and simply move to the next/new/previous record without anything happening. I don't think the Form BeforeUpdate is doing the code in the right place.

I need the code to run when I move between any two records, which doesn't seem to be happening. Any ideas if there is even a place to put the code which'll do that?

Essentially, I need to "lock" the record until all the criteria I have set have been met (but not by using .dirty).

IRO the mousewheel, I've seen that one, and it seems to be the only way of doing it. Will have to check it out some more, but working for a large company with very strict download/install policies with users on many different PCs, not sure how do-able it will be. If I get the problem above sorted, that should (hopefully) negate the need.

Thanks again for all your help, guys!
 
Upvote 0
Hi CSBB,

Strange -- like I said, I ran a test on a dummy system using BeforeUpdate, which fires every time a record is changed -- that's what I assumed you wanted. It worked fine under that scenario.
If, instead, you want the code to run every time you switch records, OnCurrent (which fires when a new record is brought up, but not when you leave a record, if you get my drift) should do it. I'd suggest having the code both places, so you can capture any movement.

Denis
 
Upvote 0
Hi again Denis.

Sorry, probably should have explained the problem a little better.

Thanks for all your help and for the tip, though! I really do appreciate it...

Cheers,
CSBBB
 
Upvote 0

Forum statistics

Threads
1,221,852
Messages
6,162,431
Members
451,765
Latest member
craigvan888

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top