Referencing one form from another

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • joancabianna
    New Member
    • Mar 2008
    • 3

    Referencing one form from another

    Hello,

    What I am trying to do is have one form loop through its combo boxes and check to see if the value is a key word like Query_Form or Query_Form2. What I then want to happen is in either case to call another form that does on the fly calculations and then stores them in separate queries.

    On this new calculation form I want to have a way of saying something along the lines of
    If 'the other form' says Query_Form .. then call this version of the query
    ElseIf 'the other form' says Query_Form2 ... then call this version of the query

    My Code so far is as follows..

    For the first form:

    Code:
      For i = 1 To 29
            If Me.Controls("cboField" & i) = "Query_Form" Then
            'Opens frmVarCalc form as a dialog box so user must take action before rest of code is run
            DoCmd.OpenForm "frmVarCalc", , , , , acDialog
            ElseIf Me.Controls("cboField" & i) = "Query_Form2" Then
            DoCmd.OpenForm "frmVarCalc", , , , , acDialog
            End If
        Next i
    For the calculation form I then have:

    Code:
    If Forms!Make_Report.Controls() = "Query_Form" Then
        Call fCreateQueries("VarCalc_Query")
        Call fCreateUpdateQueries("Update_Projects")
    ElseIf Forms!Make_Report.Controls() = "Query_Form2" Then
        Call fCreateQueries("VarCalc_Query_Two")
        Call fCreateUpdateQueries("Update_Projects_Two")
    End If
    I know the mistake is most likely in the Forms!Make_Repo rt.Controls() statement, but I don't know how to check which combo box on the other form it is.

    Any help would be greatly appreciated. Thanks!
  • Stewart Ross
    Recognized Expert Moderator Specialist
    • Feb 2008
    • 2545

    #2
    Hi. You can refer to controls on another form by providing the name of the control just as you have done within the main loop:

    Forms!formname. Controls(contro lname) or
    Forms(formname) .Controls(contr olname) amongst others.

    However, if you don't know which control name to refer to it would suggest that your current design is somewhat flawed. If it is not apparent to you how is it going to be for your users?

    Looping through 29 controls on one form to check whether or not to use some form of query by form is required seems a bit odd really, but without knowing more about why you are doing so I can't comment further.

    -Stewart

    Comment

    • joancabianna
      New Member
      • Mar 2008
      • 3

      #3
      The reason I need to loop through the comboboxes is because they help set fields for a dynamic report and the user will want to change which columns fall where each time they create the report.

      Thanks for your help, I've found a post that suggests setting a global variable to be either Query_form or Query_form2 so that the second form can reference it. So far it seems to be working!

      Thanks again!

      Comment

      Working...