Solved

How to identify the name of current subform that's in focus on access form

Posted on 2011-09-19
11
393 Views
Last Modified: 2012-06-21
Hi,
I have a form named frmStudentServiceAndQtrDetails.  On it is a subform named frmsubQtrClassDetails.  
I have a button on the parent form named Help.  I work with blind users, and I'd like them to be able to Alt h to open an input box, informing them exactly what form they are in.  (It is a busy form and would be easy to get lost in.)  My input box works fine except I can seem to get the right syntax to find that we are in the subform.  
Any ideas appreciated.  Thanks!
0
Comment
Question by:Not2ruthless
  • 5
  • 3
  • 2
11 Comments
 
LVL 61

Expert Comment

by:mbizup
ID: 36564448
If you have a button on your subform, you can use the following code to determine the name of the subform that the button is on:

MsgBox Me.ActiveControl.Parent.Name


<I have a button on the parent form named Help.>
The trouble I see with this approach is that if a user is editing subform data and clicks a button on the main form to determine which subform they were editing, they are no longer in the subform - but back in the main form. (so the answer to the question "where am I" when clicking a button on the main form would always be "the main form")
0
 

Author Comment

by:Not2ruthless
ID: 36564463
Thanks.  The Button itself is on the main form.  I'd like to use that same help button to determine what form (the main or sub), that I'm in.  If it's not possible, I could put two help buttons but would like to avoid it
Ruth.  
0
 
LVL 61

Expert Comment

by:mbizup
ID: 36564476
<< to determine what form (the main or sub), that I'm in >>

That's the problem right there... as soon as you click a main form button you are in the main form, regardless of whether you were in the main or sub form before clicking the button.



0
Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

 

Author Comment

by:Not2ruthless
ID: 36564498
Just for kicks, is there any syntax at all to determine the name of the subform one is in at any given time?  (Pretending I don't have a Help Button that would divert focus).  Now I'm just curious :)
0
 
LVL 47

Accepted Solution

by:
Dale Fye (Access MVP) earned 125 total points
ID: 36564523
Are your "blind users" totally blind or just partially?

I generally use conditional formatting on all of my textboxes and combo boxes which changes the background color of the control when the control has the focus.

as mbizup states, if you are clicking a button on the main form, or using Alt_H as a shortcut for that control, then you have a minor, but not insurmountable problem.

You can use the Screen.Previous control property to identify the control that had the focus prior to clicking on your Help button on pressing Alt_H.  Assuming your Alt_H is a shortcut to cmd_Help, it might look like:

Private Sub cmd_Help_Click

    if Screen.PreviousControl.ControlType = acSubform then
        msgbox "You are on subform: " & Screen.PreviousControl.Name
    Else
       ' some other code here
    end if

End sub

If you want to indicate what control had the focus inside that subform, you have to drill down

    if Screen.PreviousControl.ControlType = acSubform Then
        set frm = Screen.PreviousControl.Form
        set ctrl = frm.ActiveControl
        msgbox "You are in the " & ctrl.name & " control on subform: " & frm.name
    end if




If you are using the forms Key_Preview and KeyDown event to check for Alt_H
0
 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
ID: 36564527
If you are using KeyPreview and the KeyDown event to test for Alt_H, then you really don't have a problem.
0
 

Author Comment

by:Not2ruthless
ID: 36564547
Fyed, the previous control did the trick.  I work with totally blind users, but like to make it user friendly for us photo-dependents as well!!

Thanks mBizup and Fyed!!
0
 

Author Comment

by:Not2ruthless
ID: 36564570
I've requested that this question be closed as follows:

Accepted answer: 0 points for Not2ruthless's comment http:/Q_27316697.html#36564547

for the following reason:

Didn't mean to use my comment as the solution, sorry!
0
 

Author Comment

by:Not2ruthless
ID: 36564571
I accidently added a comment before accepting solution by Fyed.  Would like to retract that and Accept Fyed's solution.
So am objecting to my own non-solution :)
0
 
LVL 61

Expert Comment

by:mbizup
ID: 36566021
fyed,

<< Screen.PreviousControl.Name >>

Nice trick!  

I was envisioning some convoluted method of determining the user's "last location" by using global variables.

It makes sense that there is a "PreviousControl" for this type of need...

I learned something new :)


Ruth,

<So am objecting to my own non-solution :) >

Your objection cancelled the pending closure which was marking your answer as accepted... the button you need to accept fyed's solution should be visible to you again.

0

Featured Post

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Some sers suddenly getting error popup msg 28 89
Normalization of a table 19 74
Access on Mouse move 5 34
DSN-LESS connection to MS Access database 6 30
Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question