Clicky

I have a button on the mainform (cmdHelp) that I want a user to click when they are on a specific field on this mainform (frmEmployee_Audits), and when they click the button, I want it to open the help form (frmHelpContent) and the form's criteria to be the DLookup that I have.  So when the form (frmHelpContent) opens, based off of the DLookup, the lookup for the content of the field (helpbox) shows on the open form (frmHelpContent).

I am trying to create a help file for my database.

When I click the (cmdHelp) button, it opens the form I want (frmHelpContent), but the field (helpbox) is empty.  This should contain the data in the (HelpContent) field of the table (tblHelp).

In the table [tblHelp], I have 2 fields:

  1.  ControlName  (this contains the names of the controls on the main form)
  2.  HelpContent  (this contains the help information for the ControlName)

I have included the code for the button (cmdHelp)  that I want the user to click to lookup help for whatever field the user is currently in.

Thanks,
gdunn
 Private Sub cmdHelp_Click() Dim HelpVal As String  HelpVal = Nz(DLookup("[HelpContent]", "tblHelp", "[ControlName] = '" & Me.Name & "'"))  DoCmd.OpenForm "frmHelpContent" Forms.frmhelpcontent.helpbox.Value = HelpVal  End Sub                             
1: 2: 3: 4: 5: 6: 7: 8: 9: 

Select allOpen in new window

asked 12/13/2011 05:58

gdunn59's gravatar image

gdunn59 ♦♦


12 Answers:
This "Me.Name" will return the name of the form that has the cmdHelp button, was that your intention?
link

answered

Runrigger's gravatar image

Runrigger

No I need it to do the DLookup based off of the Control Name on the form (the field that the user is currently sitting in) and the Control Name in the tblHelp matches.

Thanks,
gdunn59
link

answered 2011-12-13 at 14:57:47

gdunn59's gravatar image

gdunn59

Is this what you are trying to do (get the name of the active control)?


1:
HelpVal = Nz(DLookup("[HelpContent]", "tblHelp", "[ControlName] = '" & Me.ActiveControl.Name & "'"))

link

answered 2011-12-13 at 15:13:49

mbizup's gravatar image

mbizup

Yes
link

answered 2011-12-13 at 15:25:22

gdunn59's gravatar image

gdunn59

mbizup, you can't quite use that because the cmdButton will be the active control at the point of click and not the Text Box

You need to declare a private form variable and call it LastControl

Then on the Lost Focus event of the various controls, set the LastControl variable equal to its name;

example;
Private LastControl As String

Private Sub Text2_LostFocus()
    LastControl = "Text2"
End Sub

The use this;
HelpVal = Nz(DLookup("[HelpContent]", "tblHelp", "[ControlName] = '" & LastControl & "'"))


link

answered 2011-12-13 at 15:27:27

Runrigger's gravatar image

Runrigger

Runrigger:

Not sure what you mean by declare a private form variable.

Thanks,
gdunn59
link

answered 2011-12-13 at 15:42:06

gdunn59's gravatar image

gdunn59

Runrigger:

Ignore my last posting.  I think I got it to work.

I will play around with it a little more and let you know.

Thanks,
gdunn59
link

answered 2011-12-13 at 16:02:58

gdunn59's gravatar image

gdunn59

I missed the part about the command button - was thinking of this being called directly from the click event in question.


Runrigger has posted a good solution but you can also simply use Screen.PreviousControl like this:


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

answered 2011-12-13 at 16:21:20

mbizup's gravatar image

mbizup

mbizup, its why I love this site, never a day wasted learning new techniques ;-)
link

answered 2011-12-13 at 16:48:16

Runrigger's gravatar image

Runrigger

I was looking in the forms properties/event to see if there was a previous control, never thought about "screen"
link

answered 2011-12-14 at 00:31:17

Runrigger's gravatar image

Runrigger

Runrigger,

I know what you mean - I've been using Access for years and just learned about Screen.PreviousControl a couple of weeks ago (from 'fyed', I think).
link

answered 2011-12-14 at 00:31:55

mbizup's gravatar image

mbizup

This worked great.  

Runrigger's solution also worked, but I liked your solution because I didn't have to add that extra code to each field.

Thanks,
gdunn59
link

answered 2011-12-14 at 02:35:44

gdunn59's gravatar image

gdunn59

Your answer
[hide preview]

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Tags:

×18

Asked: 12/13/2011 05:58

Seen: 129 times

Last updated: 12/15/2011 06:43