Results 1 to 7 of 7
  1. #1
    3 Star Lounger
    Join Date
    Nov 2001
    Location
    Brisbane, Queensland, Australia
    Posts
    330
    Thanks
    10
    Thanked 0 Times in 0 Posts

    Check if subform (Acc 97 sr2 on 95b)

    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??) <img src=/S/confused.gif border=0 alt=confused width=15 height=20> <font face="BrushScript BT">But how???????</font face=brush>

    **********************
    "Heading for the deep end"

  2. #2
    Super Moderator
    Join Date
    Jun 2002
    Location
    Mt Macedon, Victoria, Australia
    Posts
    3,993
    Thanks
    1
    Thanked 45 Times in 44 Posts

    Re: Check if subform (Acc 97 sr2 on 95b)

    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.
    Regards
    John



  3. #3
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Check if subform (Acc 97 sr2 on 95b)

    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.
    Charlotte

  4. #4
    3 Star Lounger
    Join Date
    Nov 2001
    Location
    Brisbane, Queensland, Australia
    Posts
    330
    Thanks
    10
    Thanked 0 Times in 0 Posts

    Re: Check if subform (Acc 97 sr2 on 95b)

    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.
    "Heading for the deep end"

  5. #5
    3 Star Lounger
    Join Date
    Nov 2001
    Location
    Brisbane, Queensland, Australia
    Posts
    330
    Thanks
    10
    Thanked 0 Times in 0 Posts

    Re: Check if subform (Acc 97 sr2 on 95b)

    Thanks for the idea, I will attempt to work out how to check the status.
    "Heading for the deep end"

  6. #6
    Star Lounger
    Join Date
    Aug 2001
    Location
    GA
    Posts
    52
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Check if subform (Acc 97 sr2 on 95b)

    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

  7. #7
    3 Star Lounger
    Join Date
    Nov 2001
    Location
    Brisbane, Queensland, Australia
    Posts
    330
    Thanks
    10
    Thanked 0 Times in 0 Posts

    Re: Check if subform (Acc 97 sr2 on 95b)

    Thank you Bruce, just what I needed. Everything now works just the way I want.
    "Heading for the deep end"

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •