Referencing a Subform from two different forms.

  • Thread starter David_Williams_PG ()
  • Start date
D

David_Williams_PG ()

Am trying to reference a Subform - "frm_find_code" in a module to cover two
different forms in which it lives ! Which are :-

"Frm_CSR_input" and "Frm_OGI_Investigation"

Easy to assign to one from only - Form_t = "Frm_CSR_input" Net below
expression is fine

Ean6_f = Forms(form_t)!frm_find_code!EAN6

But the only solution I can think of to get both variables / forms to work
is to use an SQL in the Form load procedure to write speciific form to a
table :-

DoCmd.RunSQL "UPDATE Tbl_varables " & _
"SET SetVarable = ""Frm_CSR_input"", " & _
"SetNo_Varable = 1 " & _
"WHERE Tbl_varables.Selection=1;"

and then from within the module pick up the form name :-

Set DB = CurrentDb()
Set rst = DB.OpenRecordset("SELECT Tbl_varables.SetVarable FROM
Tbl_varables " & _
" WHERE (((Tbl_varables.Selection)=1));")

rst.MoveFirst
form_t = rst.Fields("SetVarable").Value
rst.Close

This works but come on their must be an easier way !!


DW
 
M

Marshall Barton

David_Williams_PG said:
Am trying to reference a Subform - "frm_find_code" in a module to cover two
different forms in which it lives ! Which are :-

"Frm_CSR_input" and "Frm_OGI_Investigation"

Easy to assign to one from only - Form_t = "Frm_CSR_input" Net below
expression is fine

Ean6_f = Forms(form_t)!frm_find_code!EAN6
[snip convoluted idea]


Any form can refer to itself by using the Me keyword.

Any subform can refer to its main form by using the Parent
keyword.

Note that your naming is confusing. The syntax Form_ and
Report_ have specific meaning in Access (i.e. Form_t refers
to the class object of a form named t)
In general you should not create names that are used by
Access, VBA, or SQL.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top