none
VBA Code Event RRS feed

  • Question

  • Hi,

    I have a form in Access 2007 connected to two datatables called "Staff" and "Documents"; there's a command button in this form.  The button starts a VBA event which loads a page in Internet Explorer.  The webpage contains a webform with two fields, these are called "trl" and "idc".

    My database fields [Staff].[translate] are equivalent to trl on the Webpage, and [Documents].[Card Number] is equivalent to idc.  I have successfully tested the command button to open and then load the webform with example string values for trl and idc using the syntax:

    Call IE.Document.GetElementByID("trl").SetAttribute("value", "Example")

    However I would like to load the webform to replace "Example" with real values for [Staff].[translate] and [Documents].[Card Number], as displayed on the form for that unique recordset.  I would be grateful if somebody could point me in the right direction.  Obviously I'm a VBA novice and I'm having trouble finding the right instructions.  Kind Regards, Brandon

    Friday, September 11, 2015 5:50 PM

Answers

  • Hi. When trying to refer to values on the form when the code is executed by the same form, you can use the "Me" keyword as a reference to the current form. So, for example, you could try something like:

    Call IE.Document.GetElementByID("trl").SetAttribute("value", Me.trl)

    Assuming the control's name on your form is "trl."

    Hope that helps...

    Friday, September 11, 2015 6:06 PM
  • PS Since writing, I have edited my subform to include the field I required in the related table.  This allows the Me.XXX address to find the record as a work-around solution.  I would still be interested to see the correct syntax for addressing fields directly in the parent form, thanks

    Hi Brandon,

    When you are in a Subform, you can refer to the Main form using:     Me.Parent

    From a Subform you can also refer to other Subforms using:    Me.Parent!<subformcontrol><control on subform>

    Imb.

    Saturday, September 12, 2015 8:07 AM

All replies

  • Hi. When trying to refer to values on the form when the code is executed by the same form, you can use the "Me" keyword as a reference to the current form. So, for example, you could try something like:

    Call IE.Document.GetElementByID("trl").SetAttribute("value", Me.trl)

    Assuming the control's name on your form is "trl."

    Hope that helps...

    Friday, September 11, 2015 6:06 PM
  • Thank you very much for helping, and so quickly, your suggestion worked beautifully.

    "trl" on the Webform is equivalent to "translate" in my [Staff] table, so your advice to use

    Call IE.Document.GetElementByID("trl").SetAttribute("value", Me.translate) , identified the correct record in the form.

    My only remaining problem is caused by the current design of my master Form - The command button is located inside a subform; this subform displays records from my [Staff] datatable and the VBA event works perfectly for records inside this [Staff] table (using your Me.XXX suggestion).

    The master Form displays records from another table called [Documents].  The Webform also needs a field from the Documents table but I don't know how to focus the command button event to fields outside the subform.  I'd be grateful for any advice. (In case it's relevant, the subform and master form have a simple master/child relationship via a single common field).  Kind Regards, Brandon

    PS Since writing, I have edited my subform to include the field I required in the related table.  This allows the Me.XXX address to find the record as a work-around solution.  I would still be interested to see the correct syntax for addressing fields directly in the parent form, thanks
    • Edited by BrandM Saturday, September 12, 2015 8:01 AM
    Saturday, September 12, 2015 7:43 AM
  • PS Since writing, I have edited my subform to include the field I required in the related table.  This allows the Me.XXX address to find the record as a work-around solution.  I would still be interested to see the correct syntax for addressing fields directly in the parent form, thanks

    Hi Brandon,

    When you are in a Subform, you can refer to the Main form using:     Me.Parent

    From a Subform you can also refer to other Subforms using:    Me.Parent!<subformcontrol><control on subform>

    Imb.

    Saturday, September 12, 2015 8:07 AM
  • That's great, I'm very grateful to both of you for helping me with this code.  The event runs perfectly now, you've saved me so much time. Thank you
    Saturday, September 12, 2015 9:26 AM
  • Hi BrandM. You're welcome! Imb and I were happy to assist. Good luck with your project.
    Saturday, September 12, 2015 3:16 PM