50,237 Members
3 added today
248,638 Resources
83 added today

All Devdex   All VBdex   Current Category
VBdex > Forums & Newsgroups > Newsgroups > comp.databases.ms-access Add this category to My Favorites

View Message Thread  (8 replies)

Results 1 - 9 of 9

How do I determine if the FormHeader has focus in a continuous form ? Add this thread to My Favorites
From: Greg (codepug@gmail.com)
Date Posted: 7/28/2010 7:21:00 AM

In a continuous form, I capture the keydown event to determine if the
Del key was pressed. I have a routine that processes the Delete as I
see fit.
However, if the user is in a control in the Form Header, I do not want
the del Key
processed.

How do I determine if the forms header has control ? This may solve my
problem.

Thanks

Re: How do I determine if the FormHeader has focus in a continuous form ?
From: Salad
Date Posted: 7/28/2010 9:36:00 AM

Greg (codepug@gmail.com) wrote:

> In a continuous form, I capture the keydown event to determine if the
> Del key was pressed. I have a routine that processes the Delete as I
> see fit.
> However, if the user is in a control in the Form Header, I do not want
> the del Key
> processed.
>
> How do I determine if the forms header has control ? This may solve my
> problem.
>
> Thanks

I created a function
Private Function Junk()
     MsgBox Me.ActiveControl.Name & " " & Me(s).Tag
End Function

Then I selected the controls for the header and selected the property
sheet and set the tag to "Header". Then set the GotFocus event to
    =Junk()

IOW, I suppose one could check the control's tag. This is an option,
others may have a better method.

Re: How do I determine if the FormHeader has focus in a continuous form ?
From: Marshall Barton
Date Posted: 7/28/2010 11:23:00 AM

Greg (codepug@gmail.com) wrote:

>In a continuous form, I capture the keydown event to determine if the
>Del key was pressed. I have a routine that processes the Delete as I
>see fit.
>However, if the user is in a control in the Form Header, I do not want
>the del Key
>processed.
>
>How do I determine if the forms header has control ? This may solve my
>problem.


I answered this in mpa queries yesterday.

    Try checking the active control's Section property.
        0 - Detail
        1 - Header
        2 - Footer

If you did not follow that, here's a skeletal example:
    If Me.ActiveControl.Section = 1 Then
        'in detail section, do somerhing
    Else
        ' not in detail, do nothing
    End If

--
Marsh

Re: How do I determine if the FormHeader has focus in a continuous form ?
From: Stuart McCall
Date Posted: 7/28/2010 11:29:00 AM

<codepug@gmail.com> wrote in message
news:656e44b6-ee48-4bc8-8789-d92b32299b32@z10g2000yqb.googlegroups.com...
> In a continuous form, I capture the keydown event to determine if the
> Del key was pressed. I have a routine that processes the Delete as I
> see fit.
> However, if the user is in a control in the Form Header, I do not want
> the del Key
> processed.
>
> How do I determine if the forms header has control ? This may solve my
> problem.
>
> Thanks
>

Select Case Me.ActiveControl.Section
    Case acHeader
        'Don't process Delete
    Case acDetail, acFooter
        'Process Delete
End Select

Re: How do I determine if the FormHeader has focus in a continuous form ?
From: Stuart McCall
Date Posted: 7/28/2010 11:33:00 AM

Also, don't forget to discard the Delete keypress with:

KeyCode = 0

Re: How do I determine if the FormHeader has focus in a continuous form ?
From: Greg (codepug@gmail.com)
Date Posted: 7/29/2010 7:10:00 AM

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

Re: How do I determine if the FormHeader has focus in a continuous form ?
From: Stuart McCall
Date Posted: 7/29/2010 4:21:00 PM

<codepug@gmail.com> wrote in message
news:25b1ed1e-1e88-4b54-91a8-6a5f9ef9d227@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

Re: How do I determine if the FormHeader has focus in a continuous form ?
From: Greg (codepug@gmail.com)
Date Posted: 7/30/2010 7:17:00 AM

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

Re: How do I determine if the FormHeader has focus in a continuous form ?
From: Jon Lewis
Date Posted: 7/30/2010 8:35:00 AM

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@gmail.com> wrote in message
news:0b66b401-e937-4bb1-b25c-b612fe3b9052@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

Results 1 - 9 of 9

 

Would you like to track this thread?

By adding this News Thread to your Favorites Area you can refer to it later with just a click of the mouse. Also you can optionally be notified instantly whenever there are any replies posted to this Thread. To add this Thread to your Favorites Area just click on the red arrow next to the subject of the thread above Add this thread to My Favorites.



Credit Card Payment Control
Supports over 25 companies
Managed ASP.NET Solution
Direct Processor Support

ASP ArticlesThis category has been added to your weekly newsletter
ASP Web Sites
ADSI & WSH BooksThis category has been added to your weekly newsletter
FREE ComponentsThis category has been added to your weekly newsletter
ASP EventsThis category has been added to your weekly newsletter
ASP HeadlinesThis category has been added to your weekly newsletter

CSharp ArticlesThis category has been added to your weekly newsletter
C# Web SitesThis category has been added to your weekly newsletter

SQL ArticlesThis category has been added to your weekly newsletter
SQL Events
SQL HeadlinesThis category has been added to your weekly newsletter
SQL Jobs

Jobs in CaliforniaThis category has been added to your weekly newsletter

XML ArticlesThis category has been added to your weekly newsletter
XML BooksThis category has been added to your weekly newsletter
XML Web Sites
XML Tutorials

free asp host

"Alex Homer"This search has been added to your weekly newsletter

Edit My Favorites Edit Profile & Favorites

 

 

 

 

 




Developersdex Home | ASP | C# | SQL | VB | XML | Gurus
Add Your Link | Add Your Code | FAQ | Advertise | Link To Us | Contact Us |
Copyright © 2010 Developersdex™. All rights reserved.