Solved Refer To Sub Form In Main Form :

ahmedjamalaboelez

Ahmed J. Aboelez
Local time
Today, 16:02
Joined
Feb 25, 2015
Messages
79
Good Day Access World

I want to refer to sub form inside the form class so It can be easy not to edited multi lines in every for
Following code I use but giving error that VBA not recognize sub form
Code:
' Define Current Form And Sub Form
        Dim CurrentForm As Form
        Dim HeaderSubForm As SubForm
        Dim LinesSubForm As SubForm
        '--------------------------
        Dim CurrentFormName As String
        Dim HeaderSubFormName As String
        Dim LinesSubFormName As String

Code:
    ' On Even Form Open
    
    CurrentFormName = "FrmDatabases"
    HeaderSubFormName = "sub_databases_view"
    LinesSubFormName = "sub_dbconnections_view"
    Set CurrentForm = Forms(CurrentFormName)
    Set HeaderSubForm = CurrentForm!SubForms(HeaderSubFormName)
    Set LinesSubForm = CurrentForm!SubForms(LinesSubFormName)

Then when I want to call function in sub form or ask sub form to requery

Code:
  'Call Function in subform
   Forms!CurrentForm!HeaderSubForm.Form.ReloadMe
 
  'Call Sub Form Recuery
   CurrentForm!HeaderSubForm.Requery
  
   'Setfocus
   CurrentForm!HeaderSubForm.SetFocus


On compiling code no errors
but when i run the form following error comes to me
1665650999702.png

Any help appreciated
Thanks
A.J
 
you declare them All as Form.
Code:
' Define Current Form And Sub Form
        Dim CurrentForm As Form
        Dim HeaderSubForm As Form
        Dim LinesSubForm As Form
        '--------------------------
        Dim CurrentFormName As String
        Dim HeaderSubFormName As String
        Dim LinesSubFormName As String


Code:
    ' On Even Form Open
    
    CurrentFormName = "FrmDatabases"
    HeaderSubFormName = "sub_databases_view"
    LinesSubFormName = "sub_dbconnections_view"
    Set CurrentForm = Forms(CurrentFormName)
    Set HeaderSubForm = CurrentForm(HeaderSubFormName).Form
    Set LinesSubForm = CurrentForm(LinesSubFormName).Form
 
to Requery:

CurrentForm.Requery
HeaderSubForm.Requery
LinesSubform.Requery
 
i replaced code but this error show up to me in this line
Code:
  Forms!CurrentForm!HeaderSubForm.Form.ReloadMe
1665652187885.png
 
see post #3, you already have them as object, so you don't use:

Forms!CurentForm!HeaderSubform, etc.

if you want to use HeaderSubform, just use:

HeaderSubform.Requery
 

Users who are viewing this thread

Back
Top Bottom