From: Stuart McCall on
<codepug(a)gmail.com> wrote in message
news:25b1ed1e-1e88-4b54-91a8-6a5f9ef9d227(a)k19g2000yqc.googlegroups.com...
> Thanks Stuart
>
> I tried your code, however I'm trapping the following error that
> occurs when in the form detail area.
>
> 2472 / The espression you entered required the control to be in the
> active window / Form_KeyDown
>
> Any ideas?
>
> Private Sub Form_KeyDown(KeyCode As Integer, SHIFT As Integer)
> '*************************************************************
> 'UTIL: Key interpreter. Restricts keys.
> On Error GoTo Err_Handler
> If KeyCode = 35 Or KeyCode = 36 Then
> ' Shut off the Home & End key in this module.
> KeyCode = 0
> End If
> If KeyCode = 46 Then 'Del key was pressed
> Select Case Me.ActiveControl.Section 'Process a record delete
> Case acHeader, acFooter
> 'In the form header, process Del key normally
> Case acDetail
> Call DelRecord
> End Select
> End If
> KeyCtrl = "PgUpDnON"
> Call KbdSecurity(KeyCtrl, KeyCode, SHIFT)
> Exit_Point:
> Exit Sub
> Err_Handler:
> MsgBox Err.Number & " / " & Err.DESCRIPTION & " / " &
> "Form_KeyDown"
> Resume Exit_Point
> End Sub
>
>
> Private Sub DelRecord()
> If MsgBox("You are about to DELETE 1 record selected by pointer."
> & vbCr & vbLf & vbCr & vbLf & _
> "If you click Yes, you won't be able to undo this Delete
> operation" & vbCr & vbLf & _
> "Are you sure you want to Delete this record ?",
> vbQuestion + vbYesNo, _
> "Delete Record ?") = vbYes Then
> Me.T_SICK_DELFLAG = True
> Me.DELDATE = Now()
> Me.Requery
> Call GoToBottom
> End If
> End Sub

Which line does the code break on (temporarily disable your error handler to
find out) ?

Also, try:

Case acDetail
KeyCode = 0
Call DelRecord


From: Greg (codepug on
I discovered that the error occurs when the Record Selector in the
continuous form has focus.
I am able to accomplish what I was looking to do, however I have to
manage it by trapping the error
code & processing from there. I wonder if there is a way to identify
when the record selector has focus?

Thanks
Greg
From: Jon Lewis on
I haven't tested this extensively but it does seem to work.

Every Access Form has a Windows Handle which is a unique runtime identifier
for the Form's Window. These identifers are used for Windows API functions.
The Access property that exposes this for a Form is Hwnd as in Me.Hwnd. But
in fact, this property is actually the handle for the Record Selectors of
the Form. Although Access controls are not windows in their own right
(unlike VB controls) they do acquire a Windows Handle when they have focus.
So have a look at the code below which uses the Windows API function
GetFocus to get the Handle of whatever has the focus and adapt for your
needs:

Option Compare Database
Option Explicit

Private Declare Function GetFocus Lib "user32" () As Long 'in Declarations
section of the Form Class Module

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 46 Then
Dim lFocus As Long
lFocus = GetFocus
If lFocus = Me.Hwnd Then
MsgBox "Record Selector has focus"
Else
MsgBox "Focus is elsewhere"
End If
End If
End Sub

Jon


<codepug(a)gmail.com> wrote in message
news:0b66b401-e937-4bb1-b25c-b612fe3b9052(a)c10g2000yqi.googlegroups.com...
>I discovered that the error occurs when the Record Selector in the
> continuous form has focus.
> I am able to accomplish what I was looking to do, however I have to
> manage it by trapping the error
> code & processing from there. I wonder if there is a way to identify
> when the record selector has focus?
>
> Thanks
> Greg