opening corresponding forms or reports

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kledki
    New Member
    • Jul 2019
    • 20

    opening corresponding forms or reports

    I am working in Microsoft Access 2010.

    I have a form called "Production Report." There are several input fields on this form, one of which is called "Format."

    I also have several other forms, Group2, that correspond to the different values that can be entered in "Format." For example, the "Format" field can be populated with either A, B, C, or D. Based upon which one of these is entered into the "Format" field, what I am trying to do is make it so that the corresponding form is automatically pulled up once the field is populated so that the user doesn't have to take any additional action to open the form from Group2. I would then like the form from Group2 to print on the backside of the "Production Report." I am fairly new to Access, and don't know if this is even possible let alone how to go about doing it.

    I also have all of the Group2 forms in the form of reports if that makes anything easier.
    I've hit a wall trying to figure this out. Any help would be greatly appreciated!
  • twinnyfo
    Recognized Expert Moderator Specialist
    • Nov 2011
    • 3653

    #2
    kledki,

    Some thoughts and also a minor caution.

    First, What youa re trying to do with opening a Form based upon the value of a control on a form does not sound too terribly difficult. Just use the AfterUpdate Event of the control to openthe Form (btw, I have no idea what you mean by "Group2"):

    Code:
    Private Sub txtFormat_AfterUpdate()
        Select Case Me.txtFormat
            Case "A"
                Call DoCmd.OpenForm(FormName:="YourFormNameA")
            Case "B"
                Call DoCmd.OpenForm(FormName:="YourFormNameB")
            Case "C"
                Call DoCmd.OpenForm(FormName:="YourFormNameC")
            Case "D"
                Call DoCmd.OpenForm(FormName:="YourFormNameD")
        End Select
    End Sub
    However, in your case, you may want to add some code to validate that the value entered into your control falls within the parameters of what you need.

    Second, typically we don't "print" Forms, as they are merely an interface between the user and the actual data. It is "possible" to print forms, but not in the manner you intend, as it must be printed from within the Operating system and is essentially a "screenshot " of the form (which may be what you want). But, this cannot be done in conjunction with a print job sent from the MS Access engine.

    Since you have the "Group2" (still don't know what that means) forms also in the form of reports, there may be some ways to print those reports as sub-reports on the main form, but make them either visible or invisible depending upon the value of your control--this is more involved than what is listed above, butas far as I know, it would not be impossible to do that.

    Finally, a minor caution. Because "Format" is a reserved word in MS Access, it is highly recommended that you never use that for the name of a field or control. If you notice above, although I've put the name "Format" in the name of the control, I've "renamed" the control to txtControl.

    Other than that, we would need more information before we can provide a better solution.

    Hope this hepps.

    Comment

    • NeoPa
      Recognized Expert Moderator MVP
      • Oct 2006
      • 32633

      #3
      It seems there's little left to be said. I would only add that terminology is important. Fields are data items within the record of a table or query. Items that can show data on Forms & Reports are Controls. It is also counterproducti ve to give a Form object a name that includes "Report" in it. That is just asking people to get confused, none more so than yourself.

      Otherwise Twinny's said all that needs to be.

      Comment

      • kledki
        New Member
        • Jul 2019
        • 20

        #4
        Okay, thank you guys. I see now how my terminology may have been confusing and will try to be better about that in the future. By Group2, I simply mean the group that contains forms A, B, C, and D. I have changed the name of the "format" control to "Quality Check" in order to avoid confusion. I attempted to use the code that you provided, but I'm sure I did something wrong because nothing is happening after the control is updated.
        Code:
        Private Sub Quality_Check_AfterUpdate()
        Select Case Me.txtQuality_Check
        Call DoCmd.OpenForm(FormName:="SG_Industrial")
        Call DoCmd.OpenForm(FormName:="LG_Industrial")
        Call DoCmd.OpenForm(FormName:="SG_Retail_Carton")
        Call DoCmd.OpenForm(ForrmName:="LG_Retail_Carton")
        End Select
        
        End Sub

        Comment

        • twinnyfo
          Recognized Expert Moderator Specialist
          • Nov 2011
          • 3653

          #5
          Notice lines 3, 5, 7, 9 in my code example. You have to provide the cases for which these forms will be opened.

          Comment

          • kledki
            New Member
            • Jul 2019
            • 20

            #6
            Please excuse my ignorance on this, I'm pretty new to coding within Microsoft Access. Here is my cade now but I still cannot get it to work:
            Code:
            Private Sub Quality_Format_AfterUpdate()
            Select Case Me.txtQuality_Format
            Case "A"
            Call DoCmd.OpenForm(FormName:="SG_Industrial")
            Case "B'"
            Call DoCmd.OpenForm(FormName:="LG_Industrial")
            Case "C"
            Call DoCmd.OpenForm(FormName:="SG_Retail_Carton")
            Case "D"
            Call DoCmd.OpenForm(ForrmName:="LG_Retail_Carton")
            End Select
            
            End Sub
            I'm assuming that the cases need to be more specific?

            Comment

            • twinnyfo
              Recognized Expert Moderator Specialist
              • Nov 2011
              • 3653

              #7
              You need to be more specific and define "still cannot get it to work".

              Is there an error? What is the data being stored in the text box? You said you renamed the Control "Qualit Format" but you are referring to it as "txtQuality_For mat" in the body of the procedure, but not in the name of the sub. I will tell you that naming a control "txtQualityForm at" is most correct in this situation, but you need to make all references to that control consistent.

              One sure way to find out is to insert these two lines at the top of your module:

              Code:
              Option Explicit
              Option Compare Database
              You can also make this a default for your VBA:
              Tools | Options | Editor Tab | Require Variable Declarion should be checked.

              Comment

              • kledki
                New Member
                • Jul 2019
                • 20

                #8
                By that I mean that when "QualityFor mat" is updated, nothing is happening. The other forms are not opening.
                Code:
                Private Sub txtQualityFormat_AfterUpdate()
                Select Case Me.txtQualityFormat
                Case "QualityFormat= SG Industrial"
                Call DoCmd.OpenForm(FormName:="SG_Industrial")
                Case "QualityFormat= LG Industrial"
                Call DoCmd.OpenForm(FormName:="LG_Industrial")
                Case "QualityFormat= SG Retail Carton"
                Call DoCmd.OpenForm(FormName:="SG_Retail_Carton")
                Case "QualityFormat= LG Retail Carton"
                Call DoCmd.OpenForm(FormName:="LG_Retail_Carton")
                End Select
                
                End Sub

                Comment

                • twinnyfo
                  Recognized Expert Moderator Specialist
                  • Nov 2011
                  • 3653

                  #9
                  Have you looked at m6y example and have you compared it with what you have? Can you identify any significant differences? You should fix those first.

                  After you fix those changes, I must ask, are you asking the user to type in the value into txtQualityForma t? If so, this is asking for problems, as this may cause problems when someone mistypes the entry.

                  In this case, you should create a combo box with a list of values that hte user can select from.

                  Finally, you should insert a breakpoint in your code at the beginning of the procedure to test if this code is even firing after the text box is being updated. There are a lot of things misaligned with what you have right now, but these things ought to get you headed in the right direction so we can find out why this is not working.

                  Comment

                  • twinnyfo
                    Recognized Expert Moderator Specialist
                    • Nov 2011
                    • 3653

                    #10
                    And, if you create a list box with a list of the Form names, just use the value of the combo box to open the form directly from there:

                    Code:
                    Private Sub cboQualityFormat_AfterUpdate()
                        Call DoCmd.OpenForm(FormName:=Me.cboQualityFormat)
                    End Sub

                    Comment

                    • kledki
                      New Member
                      • Jul 2019
                      • 20

                      #11
                      Firstly, the ccode example that you provided was invaluable, so thank you. Secondly, I still have a problem. So the "QualityFor mat" control is updated after a selection is made from a combo box on the same form called "Resource ID." The code that I have will work properly if "QualityFor mat" is typed in manually, but not when it is automatically updated after a selection is made from the combo box. Why is that? Does the code need to be modified to account for the combo box?

                      Code:
                      Private Sub QualityFormat_AfterUpdate()
                          Select Case Me.QualityFormat
                              Case "SG Industrial"
                                  Call DoCmd.OpenForm(FormName:="SGIndustrial")
                              Case "LG Industrial"
                                  Call DoCmd.OpenForm(FormName:="LGIndustrial")
                              Case "SG Retail Carton"
                                  Call DoCmd.OpenForm(FormName:="SGRetailCarton")
                              Case "LG Retail Carton"
                                  Call DoCmd.OpenForm(FormName:="LGRetailCarton")
                          End Select
                      End Sub
                      P.S.
                      I referred to the name of the control in question as "Quality Check" once, but that's not correct. The name of the control is "QualityFormat. " The names of the forms that I would like to open after "QualityFor mat" is updated are SGIndustrial, LGIndustrial, SGRetailCarton, and LGRetailCarton.

                      Comment

                      • twinnyfo
                        Recognized Expert Moderator Specialist
                        • Nov 2011
                        • 3653

                        #12
                        Combo Box:
                        Name: cboQualityForma t
                        Row Source Type: Value List
                        RowSource: "SGIndustri al", "LGIndustri al", "SGRetailCarton ", "LGRetailCarton "
                        Column Count: 1

                        Code:
                        Private Sub cboQualityFormat_AfterUpdate()
                            Call DoCmd.OpenForm(FormName:=Me.cboQualityFormat)
                        End Sub
                        That's all you need.

                        Comment

                        Working...