• Check if subform (Acc 97 sr2 on 95b)

    Author
    Topic
    #376362

    I have 4 forms that work fine on their own. As they all relate to different aspects of a job, I wondered if it would be possible to collect 3 of them on the 4th one as subforms on different pages of a tab control.

    This works fine except for the SQL statements that open a query and look back to a form for parameter info ( job number). As the form in this case, is opened as a subform, the query fails as the form it is looking for isn’t there.

    **********************
    Is there code which can run on open that will determine if the form is opened in its own right or as a subform so that I can vary the SQL appropriately?

    Actually, I think that the form collection could be queried to see if the form is open as a form (maybe??) confused But how???????

    **********************

    Viewing 1 reply thread
    Author
    Replies
    • #616190

      When you open a form as a subform it has a parent, which is a form.
      I am not sure what happens if it is not a subofrm, but the parent would certainly be different. So you could check the status of me.parent.
      ********Added a bit later.
      I have just checked this, and if if it is not a subform me.parent throws and error. So you could catch error “2452” – it means it is not a subform.

      • #616377

        Thanks for the idea, I will attempt to work out how to check the status.

    • #616213

      If your forms are always being opened as subforms, isn’t the job number on the parent form? Just change your references to that. If your job number is NOT on the parent form, how are you synchronizing the subforms? Your alternative is to reference the job number on the subform, but that becomes impossible if the subforms are not linked to the parent form.

      • #616376

        Actually the Parent form is sorted by account number and so the jobs are linked to it this way. The other detail forms are tied to the job by job number. I get this to work with a hidden text box on the main form that shows the value of the selected job in subform1 on tab1.

        The forms are not always opened as subforms and I want to keep the SQL right for when the form is opened by itself. Being able to open these forms as subforms are meant for odd cross referencing occasions, not general usage. Maybe I am trying to be too clever.

        I think that John’s idea of checking the parent status is the way to go.

        • #616380

          Short and sweet:
          this function below gets the job done quite nicely . call it like this in your form.
          As you know, ‘Me’ is the self reference to the form you want to check.

          if IsSubForm(Me) then
          ‘do stuff here when its a sub form
          else
          ‘do stuff here when it is opened as a regular form
          endif

          Put this in a General Module.

          Public Function IsSubForm(frm As Form) As Boolean
          ‘ Checks if a form is loaded as a sub form

          Dim STRNAME As String
          On Error Resume Next

          STRNAME = frm.Parent.Name
          IsSubForm = (Err.Number = 0)

          Err.Clear

          End Function

          • #616406

            Thank you Bruce, just what I needed. Everything now works just the way I want.

    Viewing 1 reply thread
    Reply To: Check if subform (Acc 97 sr2 on 95b)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: