Event Procedure - Return to Previous Record

DBFIN

Registered User.
Local time
Today, 00:42
Joined
May 10, 2007
Messages
205
I'm trying to create a security measure that would prevent a user from accidently paging down in a form and moving to the next record. I want to create an event macro that would fire if the user accidently paged down into the next record. The macro would simply move back to the previous record.

What event would I use to build the macro ? What action would return to previous record ?
 
Not sure exactly what you mean by "accidently paged down," but if you mean Tabbing from the last Control in the Tab Order of a Form, and moving into the Next or New Record, you can stop this behavior, in Form Design View, by going to Properties - Other and change the Cycle Property from All Records to Current Record.

Linq ;0)>
 
I really appreciate your quick response and expertise !! I did exactly what you recommended, then tested. I tested by going to the very last control, then I clicked the page down button. The view moved to the next record, which is what I'm trying to prevent. Am I missing something ?
 
People frequently refer to 'paging down' when they simply mean tabbing down or using <Enter> to run down through Records.

But if you actually mean using the <PageDown> key, the problem is that you're trying to prevent a normal, native function of the <PageDown> key. How, for instance, do you propose to differentiate between a user 'accidentally' paging down and their paging down on purpose?

You could completely disable the <PageDown> key, I suppose, but do you really want to do that? Users, especially experienced Access-users, can get testy about normal functions not working as they should.

That said, to completely disable the <PageDown> Key:

In Form Design View, with the Form, itself, selected, go to Properties - Events, scroll way down to the KeyPreview Property and set it to YES. Then add this code to the Form's code module:

Code:
Private Sub form_keydown(KeyCode As Integer, Shift As Integer)

Select Case KeyCode
  
  Case vbKeyPageDown
    Msgbox "The Page Down Key Cannot be Used!"
    Keycode = 0 
  
End Select

End Sub
Linq ;0)>
 
Last edited:
Thanks again. I sincerely appreciate your help !!
 
One addtional note. After further testing you helped me discover that setting cycle property to current record works great for tabbing. The only time it doesn't work is when pushing the page down button. Your insight was of tremendous value in designing the database.

Thanks again !!
 
If I disable the page down key with the code you provided, will this permanently disable the page down key even when a user is working on a completely different software application outside of MS Access such as MS Excel ?
 
The page down key has not been de-activated. I opened the form in design view, set KeyPreview Property to Yes, selected Database Tools, Visual Basic and added the code you provided, however I was not sure where to insert the code. The final code is below:

Update_Total
'
'------------------------------------------------------------
Function Update_Total()
On Error GoTo Update_Total_Err
Private Sub form_keydown(KeyCode As Integer, Shift As Integer)
Select Case KeyCode

Case vbKeyPageDown
MsgBox "The Page Down Key Cannot be Used!"
KeyCode = 0

End Select
End Sub

DoCmd.OpenForm "REFERRAL", acNormal, "", "", , acNormal
Forms!REFERRAL![Quote Date] = Now()
DoCmd.RunMacro "Update_Referral", , ""
DoCmd.OpenForm "RATING ENGINE", acNormal, "", "", , acNormal
DoCmd.RunMacro "Update_Primary Rating 1", , ""
DoCmd.RunMacro "Update_Primary Rating 2", , ""
DoCmd.RunMacro "Update_Primary Rating 3", , ""
DoCmd.OpenForm "RATING ENGINE 2", acNormal, "", "", , acNormal
DoCmd.RunMacro "Update_Excess Rating 1", , ""
DoCmd.RunMacro "Update_Excess Rating 2", , ""
DoCmd.OpenForm "RATING ENGINE 3", acNormal, "", "", , acNormal
DoCmd.RunMacro "Update_Total Rating1", , ""
DoCmd.RunMacro "Update_Underwriting Forms", , ""
DoCmd.OpenForm "REFERRAL", acNormal, "", "", , acNormal
DoCmd.RunCommand acCmdRefresh
DoCmd.Close acForm, "REFERRAL"

Update_Total_Exit:
Exit Sub
Update_Total_Err:
MsgBox Error$
Resume Update_Total_Exit
End Sub
 
If I disable the page down key with the code you provided, will this permanently disable the page down key even when a user is working on a completely different software application outside of MS Access such as MS Excel ?
I wouldn't think so...but why not simply test it?
 
As to it not working, I'm not surprised! You've somehow managed to place the Form_KeyDown Sub inside of your Update_Total Function!


'------------------------------------------------------------
Function Update_Total()
On Error GoTo Update_Total_Err


Private Sub form_keydown(KeyCode As Integer, Shift As Integer)
Select Case KeyCode

Case vbKeyPageDown
MsgBox "The Page Down Key Cannot be Used!"
KeyCode = 0

End Select
End Sub

DoCmd.OpenForm "REFERRAL", acNormal, "", "", , acNormal
Forms!REFERRAL![Quote Date] = Now()
DoCmd.RunMacro "Update_Referral", , ""
DoCmd.OpenForm "RATING ENGINE", acNormal, "", "", , acNormal
DoCmd.RunMacro "Update_Primary Rating 1", , ""
DoCmd.RunMacro "Update_Primary Rating 2", , ""
DoCmd.RunMacro "Update_Primary Rating 3", , ""
DoCmd.OpenForm "RATING ENGINE 2", acNormal, "", "", , acNormal
DoCmd.RunMacro "Update_Excess Rating 1", , ""
DoCmd.RunMacro "Update_Excess Rating 2", , ""
DoCmd.OpenForm "RATING ENGINE 3", acNormal, "", "", , acNormal
DoCmd.RunMacro "Update_Total Rating1", , ""
DoCmd.RunMacro "Update_Underwriting Forms", , ""
DoCmd.OpenForm "REFERRAL", acNormal, "", "", , acNormal
DoCmd.RunCommand acCmdRefresh
DoCmd.Close acForm, "REFERRAL"

Update_Total_Exit:
Exit Sub
Update_Total_Err:
MsgBox Error$
Resume Update_Total_Exit
End Sub

Delete all of the above and then paste this in:

Code:
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)

Select Case KeyCode
  
  Case vbKeyPageDown
    MsgBox "The Page Down Key Cannot be Used!"
    KeyCode = 0
  
End Select

End Sub

Code:
Function Update_Total()

On Error GoTo Update_Total_Err

DoCmd.OpenForm "REFERRAL", acNormal, "", "", , acNormal
    Forms!REFERRAL![Quote Date] = Now()
    DoCmd.RunMacro "Update_Referral", , ""
    DoCmd.OpenForm "RATING ENGINE", acNormal, "", "", , acNormal
    DoCmd.RunMacro "Update_Primary Rating 1", , ""
    DoCmd.RunMacro "Update_Primary Rating 2", , ""
    DoCmd.RunMacro "Update_Primary Rating 3", , ""
    DoCmd.OpenForm "RATING ENGINE 2", acNormal, "", "", , acNormal
    DoCmd.RunMacro "Update_Excess Rating 1", , ""
    DoCmd.RunMacro "Update_Excess Rating 2", , ""
    DoCmd.OpenForm "RATING ENGINE 3", acNormal, "", "", , acNormal
    DoCmd.RunMacro "Update_Total Rating1", , ""
    DoCmd.RunMacro "Update_Underwriting Forms", , ""
    DoCmd.OpenForm "REFERRAL", acNormal, "", "", , acNormal
    DoCmd.RunCommand acCmdRefresh
    DoCmd.Close acForm, "REFERRAL"

Update_Total_Exit:
    Exit Sub
Update_Total_Err:
    MsgBox Error$
    Resume Update_Total_Exit
End Function

Linq ;0)>
 

Users who are viewing this thread

Back
Top Bottom