Link to home
Start Free TrialLog in
Avatar of gdunn59
gdunn59

asked on

Return to Field on Main Form

I have a main form that has a ? mark on it for Help which opens a form that displays help for whatever field a user is on.

What I want to happen is when a user clicks on the ? mark when in a specific field and it opens the help form and displays the help for that field, and then the user closes the Help form, I want the focus to be set back to the field that the user was in when they clicked on the ? mark for help.

I have an exit button the Help form that closes the help form and returns to the main form.

How would I go about dong this?

Thanks,
gdunn59
Avatar of shankar_nr
shankar_nr

At this point the ? still has the focus. Assuming your tab indexes are all set, simply use SendKeys to send shift + tab to move one field back.
you can use a global variable

create a new module
then create a new global variable in the new module

such as  
Global FFocus as String
save and close the module

then on each of the textboxes in the on got focus event set the global variable's value to the name of the field.

then in the onclose event of your other form set the focus to the last control using the global variable's value

Forms![Form1].Controls(FFocus).SetFocus
Avatar of mbizup
In the ? button's click event, capture the name of the previously clicked control.  Then if you open your popup help form in Dialog mode, you can do this:


Private Sub HelpButton_Click()

   Dim strPreviousControlName as string

   strPreviousControlName = Screen.PreviousControl.Name
   DoCmd.OpenForm "frmMyHelpForm", WindowMode:=acDialog
   Me.Controls(strPreviousControlName).SetFocus

End Sub

Open in new window

This works because acDialog suspends code execution in the calling function upon opening the popup, and resumes it once the popup form is closed.
Avatar of gdunn59

ASKER

mbizup:

Your solution worked with one exception.  I have some combo boxes that are set to automatically drop-down when the combo box gets the focus.  So what is happening on those fields is when the Help Form opens the drop-down shows on the Help form that opens.

Thanks,
gdunn59
Avatar of gdunn59

ASKER

mbizup:

One other issue I am having with the help besides the combo box drop-down issue is when I get to a field that is required, and attempt to click on the ? mark for help, it keeps prompting me with the message that this is a required field.

How can I get around this if trying to look at help for a required field?

Thanks,
gdunn59
Regarding the required field messages - are they coming from code in these controls' Exit events?

If so, there is no way around it other than reworking your validation checks into a form-level event (such as the form's before update event).

The reason for this is that the control's Exit event fires before the command button's click event (ie: any requirement in the Exit event of a control has to be met *before* focus can be set to a different control such as your command button).

---

Regarding the drop-down issue, can you post a screen shot?  I tested this in a sample and what I saw was the drop down list going away when the popup opened, and returning upon closing the popup and returning focus to that field (Access 2007).
Avatar of gdunn59

ASKER

mbizup:

I've attached a screen shot of the issue I'm referring to in regards to the drop-down.

This screen shot is when I select the Region Combo-box.  If I just hit the down arrow once on the screen, the drop-down dissappears.

Thanks,
gdunn59
 Screen-Shot-of-Region-Drop-Down-.docx
Avatar of gdunn59

ASKER

mbizup:

In regards to the required field message it is coming from the On Enter Event for these fields.

Thanks,
gdunn59
Are you able to post a sample copy of your database - just the relevant forms and tables, with any sensitive data masked or removed?
(in other words, just enough of a sample to recreate this issue)
Avatar of gdunn59

ASKER

mbizup:

I will have to do this later.  Have appt to get to now.

Thanks,
gdunn59
Avatar of gdunn59

ASKER

mbizup:

Here is the database.  Don't click on or use the Switchboard because you will get an error.

Launch the frmEmployee_Audits Form and put your cursor on Employee or Manager or any of the combo box drop-down fields and then click on the blue ? mark for help.  The help form opens and the drop-down data still shows on the screen.

Thanks,
gdunn
Hi  - your database somehow did not get attached.

When using the File attach link, be sure to wait until your file uploads completely before submitting the comment (the progress bar lets you know how far along it is).  Unfortunately there is no error handling or message on the submit button to let you know that your upload hasn't finished - you just have to be careful.
Avatar of gdunn59

ASKER

mbizup:

Ok.  Let me try and attach database again.

Thanks,
gdunn59
Audit-Database--12-21-2011--for-.accdb
ASKER CERTIFIED SOLUTION
Avatar of mbizup
mbizup
Flag of Kazakhstan image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Also - just curious...

Why are you setting the cursor to the end of the help box?

It seems like it would be a more comfortable UI if the cursr were at the beginning.
I'm thinking that you are setting the cursor to the end to avoid the entire text in the box from being selected (looking like it is highlighed in black).

Unfortunately, setting the cursor to the end seems to have the effect of only displaying the last line of text for some of these entries.

I think you can get the appearance you want by setting the selection length to zero instead.  

So change the popup form's open event to:

Me.helpbox.Value = OpenArgs
Me.helpbox.SetFocus
Me.helpbox.SelLength = 0

Open in new window

Audit-Database--12-21-2011--for-.accdb
Avatar of gdunn59

ASKER

mbizup:

The new code that you told me to use for the help ? button works the only issue is that it goes to the last line of the help content so you have to scroll back up to the top to see the whole help content.  So I changed the Open Event code on the Help Form to the following (see below) and now it doesn't brings up a blank Help form instead of showing the help content.

Me.helpbox.Value = OpenArgs
Me.helpbox.SetFocus
Me.helpbox.SelLength = 0

Thanks,
gdunn59
Did you look at the modified sample database I posted?

We might have miscommunicated somewhere in the comments, but the sample does appear to work (it shows the help content).

Give it a try and let me know...

Avatar of gdunn59

ASKER

mbizup:

Ok, I will let you know the outcome.

Thanks,
gdunn59
Avatar of gdunn59

ASKER

mbizup:

I opened your database and copied the code from there and now it appears to be working.

Let me do some more testing, and I will let you know for sure.

Thanks,
gdunn59
From the sounds of it, I think that the revised OpenForm statement from http:#a37327009 was missed the first time you tried these revisions.

If the OpenArgs didn't get added to the OpenForm statement, the behavior would be exactly as you described (you wouldn't see any help content).

Avatar of gdunn59

ASKER

mbizup:

Ok.  Also, the only thing I'm still having an issue with in regards to the help is the required fields.

Thanks,
gdunn59
Which fields should I look at specifically in the sample / what exactly should I do to recreate the problem?

My gut feeling is that you cannot combine the type of data validation you are trying to do with your desired functionality for this help box for the reasons I explained here http:#a37319635  (The Enter event would have the same issues as the Exit event).



As an aside, why did you choose the Enter event, which is run as the user enters into the field instead of the Exit event which occurs after data entry is done and the user leaves the field?
Avatar of gdunn59

ASKER

mbizup:

I did use the Exit event on the required fields.

Thanks,
gdunn59
Avatar of gdunn59

ASKER

mbizup:

The required fields are:
 
    Action Required
    Action Required Reason (which is only enabled if the user chooses "Yes" for the Action Required)
    What is the status of the Audit (Draft or Completed)?

Currently, the "Action Required" field's code for forcing the user to enter a selection is commented out.

Thanks,
gdunn59
Okay - because of the order of events in Access forms there is nothing that you can do to make it work exactly the way you are trying to.  Access simply does not work that way.

The best that you can do is to move your validation checks to the Before Update event, which like a control's Exit event is cancellable.  The code would be almost the same as what you have in the Exit events.  The difference would be that the required field messages would appear when the user saves a record (unlike now, when the messages appear as soon as the user tries to leave the control).
Just hoping to clarify my earlier explanation of the control's Exit event -

- When the user clicks your help button, they are leaving the active control.

- Your Exit event handlers force the user to enter data before leaving the field (the event handlers don't care that the user is simply bringing up a help box, and there is no way to tell the code to allow the user to exit to specific controls).

So the Exit event code and the desired functionality of the help button are incompatible.


___

There is one other possible alternative that you might like better than moving the validation code to the form's Before Update event...

Instead of using a seperate help button, use the double-click event of your controls to bring up the help box.

That would bring up the helpbox, while keeping the main form's focus on the same control (so the help box opens, but the control's Exit event does not fire).
Avatar of gdunn59

ASKER

This did work, but I decided to go a whole another route because of the issues that I was having with fields that were required and for fields that needed to go to another field on the subform and then jump back to a field on the subform.  

I ended up using the solution:
    12/30/11 04:32 PM, ID: 37357052

Thanks, gdunn