Getting Current Form & Subform Info To Either Print Or Dump Into a Record

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Christina123
    New Member
    • Aug 2007
    • 22

    Getting Current Form & Subform Info To Either Print Or Dump Into a Record

    Currently working with Microsoft Office 2000 and whatever version of Access came with that.

    I am developing a database to track the comings and goings of shared tools.
    Everything works splendidly except I have printing issues, primarily I have no idea what I am doing.

    I have a form that contains the date and the info of the person doing the ordering as well as a subform that has the serial number of the part, the description and storage location. The subform is set up as datasheet view so that multiple items can be ordered at once.

    When the orderer clicks on the order button that closes the order form & subform and opens the home page. But I also need it to print off a list of what has been ordered (subform info) and the info of the person doing the order (form info).

    I have tried using the print commands in the VB docmd. part but they do not seem to do what I require. I have tried to use the queries that the form and subform are running off of to make a report that will print, this had limited succes as it printed off everything that has ever been ordered. I tried making a new query with the criteria of the order date being =now() but that did nada.

    Sooo...anyone have any suggestions to solve my quandry??
  • BradHodge
    Recognized Expert New Member
    • Apr 2007
    • 166

    #2
    It sounds like you were headed in the right direction. I would make a report based on the queries that the form is based on. Then I would add this script to your Order Button...

    Code:
    Dim strDocName as String
    Dim strLinkCriteria as String
    strDocName= "[I]YourReportName[/I] "
    strLinkCriteria="[I]YourPrimaryKey[/I] =Forms![[I]YourFormName[/I] ![[I]YourPrimaryKey[/I] ]"
    DoCmd.OpenReport strDocName, acViewNormal,strLinkCriteria
    This will open your new report with only the record containing the primary key that is showing on the form. You could change acViewNormal (above) to acViewPreview while you are playing with it. It will then do PrintPreview instead of printing out directly.

    Hope this helps,

    Brad.

    Comment

    • missinglinq
      Recognized Expert Specialist
      • Nov 2006
      • 3533

      #3
      In the future, please refrain from using all caps in your title or post! Online this is considered to be shouting makes reading the text difficult. Many members will simply ignore a poster who engages in this behavior.

      Welcome to The Scripts!

      Linq ;0)>

      Comment

      • Christina123
        New Member
        • Aug 2007
        • 22

        #4
        Well I did all of that. What happens now is it opens the report but is still showing what has been ordered. It is not recognizing the Link Criteria, that I only want the current form to print.
        This is what I have on my button thus far (this is for OnClick):

        Code:
        Private Sub cmdOrder_Click()
        Dim strDocName As String
        Dim StrLinkCriteria As String
        strDocName = "rptOrder"
        StrLinkCriteria = "OrderNumber=Forms![Order![OrderNumber]]"
        DoCmd.OpenReport strDocName, acViewPreview, StrLinkCriteria
        End Sub
        So I don't quite know where to procced from here. I have tried using the primary key on my subform, but that made no changes.

        Comment

        • puppydogbuddy
          Recognized Expert Top Contributor
          • May 2007
          • 1923

          #5
          Originally posted by Christina123
          Well I did all of that. What happens now is it opens the report but is still showing what has been ordered. It is not recognizing the Link Criteria, that I only want the current form to print.
          This is what I have on my button thus far (this is for OnClick):

          Code:
          Private Sub cmdOrder_Click()
          Dim strDocName As String
          Dim StrLinkCriteria As String
          strDocName = "rptOrder"
          StrLinkCriteria = "OrderNumber=Forms![Order![OrderNumber]]"
          DoCmd.OpenReport strDocName, acViewPreview, StrLinkCriteria
          End Sub
          So I don't quite know where to procced from here. I have tried using the primary key on my subform, but that made no changes.

          You did not quite follow the syntax that Brad gave you for StrLInkCriteria . You have a missing right parenthese in one section of the string and an extra right parentheses at the end of the string. Also, the syntax of the string assumes that OrderNumber is a text data type. If OrderNumber is a numeric data type the syntax would have to be changed.

          change this:
          StrLinkCriteria = "OrderNumber=Fo rms![Order![OrderNumber]]"

          To this:
          StrLinkCriteria = "OrderNumber=Fo rms![Order]![OrderNumber]"

          Comment

          • Christina123
            New Member
            • Aug 2007
            • 22

            #6
            OrderNumber is an auto number as it is the primary key and serves no purpose other than to give a number to the order.

            What would need to be changed since it is numeric data?

            Comment

            • puppydogbuddy
              Recognized Expert Top Contributor
              • May 2007
              • 1923

              #7
              Originally posted by Christina123
              OrderNumber is an auto number as it is the primary key and serves no purpose other than to give a number to the order.

              What would need to be changed since it is numeric data?

              Private Sub cmdOrder_Click( )
              Dim strDocName As String
              Dim lngLinkCriteria As Long
              strDocName = "rptOrder"
              lngLinkCriteria = "OrderNumbe r = " & Forms![Order]![OrderNumber]
              DoCmd.OpenRepor t strDocName, acViewPreview, lngLinkCriteria
              End Sub

              Comment

              • Christina123
                New Member
                • Aug 2007
                • 22

                #8
                Originally posted by puppydogbuddy
                Private Sub cmdOrder_Click( )
                Dim strDocName As String
                Dim lngLinkCriteria As Long
                strDocName = "rptOrder"
                lngLinkCriteria = "OrderNumbe r = " & Forms![Order]![OrderNumber]
                DoCmd.OpenRepor t strDocName, acViewPreview, lngLinkCriteria
                End Sub
                Well that kind of worked, it now shows a report of all items that have been returned. Which makes no sense as returned and ordered have no direct relationships.

                I am going to assume that I have made an error somewhere else in my database because the code should work.

                Comment

                • puppydogbuddy
                  Recognized Expert Top Contributor
                  • May 2007
                  • 1923

                  #9
                  Originally posted by Christina123
                  Well that kind of worked, it now shows a report of all items that have been returned. Which makes no sense as returned and ordered have no direct relationships.

                  I am going to assume that I have made an error somewhere else in my database because the code should work.
                  Try it this way as per the link below:

                  Private Sub cmdOrder_Click( )
                  Dim strDocName As String
                  Dim strLinkCriteria As String
                  strDocName = "rptOrder"
                  strLinkCriteria = "OrderNumbe r= '" & Forms![Order]![OrderNumber] & "'"
                  DoCmd.OpenRepor t strDocName, acViewPreview, strLinkCriteria
                  End Sub

                  Comment

                  Working...