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
LVL 1
gdunn59Asked:
Who is Participating?
 
mbizupCommented:
Okay - LOL!  I noticed that you took out my 'acDialog' suggestion.  

There is a method to my madness :)

I imagine you took it out because the code to fill the textbox on the help form was not running correctly (acDialog suspends code execution until a dialog form closes).

So - let's get the acDailog back in there and use openargs to pass the control name to your popup form.  You can set the helpbox text through the open event in your popup form.

Change your "?" button's click event to this:

Private Sub cmdHelp_Click()
On Error GoTo Err_Handler

DoCmd.Echo False

Dim HelpVal As String

HelpVal = Nz(DLookup("[HelpContent]", "tblHelp", "[ControlName] = '" & Screen.PreviousControl.Name & "'"))

Dim strPreviousControlName As String

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

DoCmd.Echo True

Exit_Handler:
    Exit Sub

Err_Handler:
    DoCmd.CancelEvent
    Cancel = True
    Resume Exit_Handler

End Sub

Open in new window


And add an open event to your help form:

Private Sub Form_Open(Cancel As Integer)
Me.helpbox.Value = OpenArgs
Me.helpbox.SetFocus
Me.helpbox.SelStart = Len(Me.helpbox)

End Sub

Open in new window




(And set the help form's auto-center propery to 'yes' for a better appearance)
0
 
shankar_nrCommented:
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.
0
 
conagramanCommented:
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
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
mbizupCommented:
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.
0
 
gdunn59Author Commented:
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
0
 
gdunn59Author Commented:
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
0
 
mbizupCommented:
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).
0
 
gdunn59Author Commented:
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
0
 
gdunn59Author Commented:
mbizup:

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

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

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

Thanks,
gdunn59
0
 
gdunn59Author Commented:
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
0
 
mbizupCommented:
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.
0
 
gdunn59Author Commented:
mbizup:

Ok.  Let me try and attach database again.

Thanks,
gdunn59
Audit-Database--12-21-2011--for-.accdb
0
 
mbizupCommented:
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.
0
 
mbizupCommented:
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
0
 
gdunn59Author Commented:
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
0
 
mbizupCommented:
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...

0
 
gdunn59Author Commented:
mbizup:

Ok, I will let you know the outcome.

Thanks,
gdunn59
0
 
gdunn59Author Commented:
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
0
 
mbizupCommented:
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).

0
 
gdunn59Author Commented:
mbizup:

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

Thanks,
gdunn59
0
 
mbizupCommented:
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).



0
 
mbizupCommented:
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?
0
 
gdunn59Author Commented:
mbizup:

I did use the Exit event on the required fields.

Thanks,
gdunn59
0
 
gdunn59Author Commented:
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
0
 
mbizupCommented:
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).
0
 
mbizupCommented:
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).
0
 
gdunn59Author Commented:
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
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.