Results 1 to 9 of 9
  1. #1
    diegomarino is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Feb 2018
    Posts
    409

    Subform name

    Hi, i use this to refer to a form objet

    Code:
          Set frm = Forms(FrmName)
    where "frm" is a form variable and "frmname" is a string variable. I specify the form object by using the form name.


    a form i used as form now is a subform and for this subform the code is not working.

  2. #2
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,803
    People have posted a link here to a page with lots of examples of object references but I don't have it. You have to understand the hierarchy of objects to make these things work. Note the distinction between subform control name vs subform name. Access will name them the same if you use the form wizard (why, oh why?). I always rename the sf control. Note that this is not correct for navigation forms (and it may go deeper than what you need). I've also assumed your code is on the main form and that you are trying to refer to the subform, not the other way around.

    referencing CONTROLS on subform:
    [Forms]![Main form name]![subform control name].[Form]![control name on subform]

    e.g.
    [Forms]![frmNP]![subNPfrm].[Form]![txtNPno]
    frmNP is main form name
    subNPfrm is name of subform control on frmNP
    txtNPno is the textbox control name
    Last edited by Micron; 03-22-2022 at 08:22 AM. Reason: clarification
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    diegomarino is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Feb 2018
    Posts
    409
    got it, i had just to add ".name"
    so it is: Forms(Forms!contatti!
    [lista candidati].Form.Name
    thanks

    edit, no i was wrong, it is not working unfortunely. I i want to specify the form object by using its name i can do only if a form is not a subform

  4. #4
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,803
    use the syntax I gave you - no parentheses. This is a double reference to the same forms collection object: Forms(Forms!
    Forms( ? ) expects either an index number (which you probably don't know) or a literal name, or a variable that contains the name only, not the rest of some hierarchy.

    EDIT -perhaps

    Code:
    Forms![contatti]!
    [lista candidati].Form.Name
    NOTE - I cannot stop the forum from breaking this into 2 lines!!
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  5. #5
    diegomarino is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Feb 2018
    Posts
    409
    i tried but it's not working. this is the code i use, it's part of a complex piece of code that i wrote to filter forms; if i want to filter the form called "lista candidati" that's a subform, i have to refer to the form itself, i can't use the name.

    Code:
    Private Sub BuildFilt(FrmName As String)   Dim db As DAO.Database
       Dim rs As DAO.Recordset
       Dim rsFilt As DAO.Recordset
       Dim FiltStr As String
       Dim Wldcrd As String
       Dim frm As Form
       Set db = CurrentDb
       If FrmName = "lista candidati" Then
          Set frm = Forms!contatti!
    [lista candidati].Form ' lista candidati è una subform e non so come si individua una maschera che è una subform tramite il nome
       Else
          Set frm = Forms(FrmName)
       End If

  6. #6
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,803
    Sorry, I thought you wanted the name. As I mentioned, it is a hierarchical thing.

    [Forms]![Main form name]![subform control name].[Form] << form itself
    [Forms]![Main form name]![subform control name].[Form].txtbox1 << a control on that form
    [Forms]![Main form name]![subform control name].[Form].Requery << a method that applies to the form
    [Forms]![Main form name]![subform control name].[Form].Name << a property of the form

    Hope that helps.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  7. #7
    diegomarino is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Feb 2018
    Posts
    409
    yes i meant the name. Maybe i make something wrong, i updated the code but it can't find the form

    Code:
    Private Sub BuildFilt(FrmName As String)   Dim db As DAO.Database
       Dim rs As DAO.Recordset
       Dim rsFilt As DAO.Recordset
       Dim FiltStr As String
       Dim Wldcrd As String
       Dim frm As Form
       Set db = CurrentDb
       If FrmName = "lista candidati" Then
          Set frm = Forms(Forms!contatti!
    [lista candidati].Form.Name) ' lista candidati è una subform e non so come si individua una maschera che è una subform tramite il nome
       Else
          Set frm = Forms(FrmName)
       End If
    that should work, cause i put the name of the form (a string i think) just like below "set frm = forms(frmname)"

  8. #8
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,803
    Code:
    Forms(Forms!contatti!
    See post 4
    This is a double reference to the same forms collection object: Forms(Forms!
    or post a zipped copy of your db, because I don't trust that the forum won't put line wraps in posted code, and I can't tell if it's happening to you too or if that's what your code really looks like.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  9. #9
    diegomarino is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Feb 2018
    Posts
    409
    here you are, sorry for delay
    the form opens at start, the you have to click the button "FILTER !!CLICK" (YOU SHOULD SEE IT) then the filter form opens, select one filter and the click on "build" button on filter form, and sse the error
    thanks

    https://hhfinanza-my.sharepoint.com/...4a9vQ?e=muEpa5

    sorry i have problem to upload the file, maybe it's too big

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 6
    Last Post: 07-08-2020, 12:26 PM
  2. Replies: 2
    Last Post: 05-29-2018, 07:39 PM
  3. Replies: 2
    Last Post: 01-21-2018, 09:19 PM
  4. Replies: 1
    Last Post: 12-05-2016, 02:23 PM
  5. Replies: 6
    Last Post: 05-05-2012, 08:43 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums