Results 1 to 6 of 6

Thread: Query help

  1. #1
    Join Date
    Feb 2005
    Posts
    46

    Unanswered: Query help

    I have 3 seperate forms form1, form2, form3 (original) and on each form there is a text box called text1.

    I have query that will select all, from table where field1 = form1.text1.text

    this works fine.

    I want to do the same query on the other 2 forms (form2, form3) is there way to get a query to check which form is loaded??

    I looking for something like

    IF form1 is loaded then
    select all, from table where field1 = form1.text1.text
    end if
    else
    etc

    cheers for your help

  2. #2
    Join Date
    Aug 2002
    Location
    Northampton, England
    Posts
    266
    This function will do just that.

    Function IsLoaded(MyFormName)
    ' Accepts: a form name
    ' Purpose: determines if a form is loaded
    ' Returns: True if specified the form is loaded;
    ' False if the specified form is not loaded.
    ' From: User's Guide Chapter 25

    Dim i

    IsLoaded = False
    For i = 0 To Forms.Count - 1
    If Forms(i).FormName = MyFormName Then
    IsLoaded = True
    Exit Function ' Quit function once form has been found.
    End If
    Next

    End Function

  3. #3
    Join Date
    Feb 2005
    Posts
    46
    So sorry to sound dim where do I put this code??

  4. #4
    Join Date
    Aug 2002
    Location
    Northampton, England
    Posts
    266
    To use this function you would do something like this:

    If Isloaded ("YourFormName") then
    'your code here
    End If

    The function must be in a module.

  5. #5
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1
    What happens if more than one form happens to be loaded? I would suggest passing the correct argument from the form itself as opposed to running out and touching all the available forms when the query gets executed.
    oh yeah... documentation... I have heard of that.

    *** What Do You Want In The MS Access Forum? ***

  6. #6
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    how about:
    Code:
    Private Function GetTarget(Optional ctlParent As Variant) As Control
        Dim ActControl As Control
        If IsMissing(ctlParent) Then
            Set ActControl = Screen.ActiveForm.ActiveControl
        Else
            Set ActControl = ctlParent.Form.ActiveControl
        End If
        If ActControl.ControlType = acSubform Then
            Set GetTarget = GetTarget(ActControl)
        Else
            Set GetTarget = ActControl
        End If
    End Function
    which will get the active control (from an arbitrary degree of subform nesting if necessary) which presumably will be the 'GoDoIt' button on the appropriate (sub)form ...not so tough to parse out the button name and concatenate in the textbox name.

    (Teddy's idea is way simpler, but i have a soft spot for bachatero´s recursion)

    izy
    currently using SS 2008R2

Posting Permissions

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