How to get a subform name using VBA

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • wassimdaccache
    New Member
    • Apr 2007
    • 222

    How to get a subform name using VBA

    Using office 2007 sp2. For each text box on my application on click event I inserted the below code to call a form called keyboard.

    Code:
    pctlname = Application.Screen.ActiveControl.Name
     Dim frmCurrentForm As Form
    Set frmCurrentForm = Screen.ActiveForm
    pfrmname = frmCurrentForm.Name
    DoCmd.OpenForm "Keyboard"
    On the keyboard from i have a button called "enterbt" on the click event I inserted the below
    Code:
     If (monitor & "") <> "" Then
      Forms(pfrmname)(pctlname) = monitor
     End If
      DoCmd.Close
    I designed this method to decrease the number of forms on my application and use only one form called keyboard where user will be able to work on the program using a touchable screen. The problem now is on the subform.

    If i have a subform the above code won't work.

    How can i get the subform name where the focus is using vba ?
    How can i assign value to the subform from the keyboard form ?
  • ChipR
    Recognized Expert Top Contributor
    • Jul 2008
    • 1289

    #2
    You may explore passing the form or form+subform name as an OpenArgs argument to the Keyboard form in DoCmd.Openform.

    Comment

    • wassimdaccache
      New Member
      • Apr 2007
      • 222

      #3
      Originally posted by ChipR
      You may explore passing the form or form+subform name as an OpenArgs argument to the Keyboard form in DoCmd.Openform.
      Thanks for your answer

      actually i have passed the subform name but i am not finding the appropriate syntax to pass to the subform the data

      Using the below code it won t work

      Code:
       If (monitor & "") <> "" Then
        Forms(pfrmname)(pctlname) = monitor
       End If
        DoCmd.Close

      Comment

      • ChipR
        Recognized Expert Top Contributor
        • Jul 2008
        • 1289

        #4
        Try this syntax to refer to a control on a subform, which is on another form:

        Forms!Mainform! Subform1.Form!C ontrolName

        Comment

        Working...