• Print ONE Invoice!

    • This topic has 21 replies, 5 voices, and was last updated 24 years ago.
    Author
    Topic
    #355423

    I’m trying to make a report, which prints out invoices, print just ONE invoice. I have a “Print Invoice” button on my Student Form and I want it to just print that student’s invoice NOT every invoice. How do I do that? I’m so confused! dizzy

    Viewing 4 reply threads
    Author
    Replies
    • #524186

      Look at Northwind.mdb or Nwind.mdb that comes with Access.
      Go to Orders Form in design view. See code for the Print Invoice Button.

    • #524403

      I created a button on the form, with the command to print the current form only. The button’s display attribute was set to display only, so that it doesn’t get printed out with the rest of the form.

      This is the VBA code behind the button (On Click [Event Procedure]):

      Private Sub PrintCurrentRecord_Click()
      On Error GoTo Err_PrintCurrentRecord_Click
      
          DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
          DoCmd.PrintOut acSelection
      
      Exit_PrintCurrentRecord_Click:
          Exit Sub
      
      Err_PrintCurrentRecord_Click:
          MsgBox Err.Description
          Resume Exit_PrintCurrentRecord_Click
      End Sub
      

      Fortunately, Access will write all of this for you. When you create the button, select Form Operations / Print Current Form for Category and Action. Place the button where it will not interfere with the remainder of the form, but will be convenient to activate.

    • #524603

      Patrick, I think that’s essentially what we did:[indent]


      strDocName = “Invoice”
      strLinkCriteria = “[InvID]=” & Forms!Invoices_Subform!InvID
      DoCmd.OpenReport strDocName, acViewNormal, , strLinkCriteria


      [/indent] Jennifer was just having a little trouble locating the elements buried in various subforms but it all appears to be sorted out now. shrug

    • #524176
      • #524180

        Thanks for the help again, Rupert. I put the code in, but now I can’t get it to print anything. What did I do wrong? Am I suppose to replace all of the code that is there with your code?

        • #524185

          You need to change these two lines.

          strDocName = “rpt_PrnOrders”
          strFilter = “tbl_Orders.OrderID = Forms!frm_Take_Orders!OrderID”

          Peplace “rpt_PrnOrders” with the name of your report

          Your report should be based on a table or query. Replace – tbl_Orders.OrderID

          • #524276

            Okay, I tried it again, Rupert. I got it to print, but now it asks for a Parameter value. What is that? And it still prints all of my invoices. Aaaaarrrggghhh!!!

            • #524277

              Hi Jennifer:
              Can you post your code here and we can take a look at it smile

            • #524278

              Okay, here’s all the code that is showing. I don’t know much about Visual Basic.

              Sub LastName_AfterUpdate()
              ‘ Find the record that matches the control.
              Me.RecordsetClone.FindFirst “[StudID] = ‘” & Me![LastName] & “‘”
              Me.Bookmark = Me.RecordsetClone.Bookmark
              End Sub

              Sub Combo33_AfterUpdate()
              ‘ Find the record that matches the control.
              Me.RecordsetClone.FindFirst “[StudID] = ‘” & Me![Combo33] & “‘”
              Me.Bookmark = Me.RecordsetClone.Bookmark
              End Sub

              Private Sub Cmd_Print_Current_Rec_Click()
              On Error GoTo Err_Cmd_Print_Current_Rec_Click

              Dim strDocName As String
              Dim strFilter As String

              DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70 ‘Save record

              strDocName = “Invoice”
              strFilter = “tbl_Invoices.InvID = Forms!frm_Student!InvID”

              DoCmd.OpenReport strDocName, acViewNormal, , strFilter

              Exit_Cmd_Print_Current_Rec_Click:
              Exit Sub

              Err_Cmd_Print_Current_Rec_Click:
              MsgBox Err.Description
              Resume Exit_Cmd_Print_Current_Rec_Click

              End Sub

              I don’t know what the other two SUBs are, though ’cause like I said, I don’t know much of anything about VBA. I hope you can help.

              Jennifer

            • #524279

              Not knowing exactly how your form and report are structured, I’m assuming the form contains a control [InvID] and can be linked to the “Invoice” report using that unique identifier. If not you might try [StudID] shrug
              [indent]


              Dim stDocName As String
              Dim stLinkCriteria As String

              stLinkCriteria = “[InvID]=” & Me![InvID]
              stDocName = “Invoice”

              DoCmd.OpenReport stDocName, acPreview, , stLinkCriteria


              [/indent]

            • #524291

              Where do I enter that code you gave me? I told you I’m pretty shrug when it comes to VBA.

              Jennifer

            • #524302

              Sorry Jennifer, just replace this whole procedure:
              [indent]


              Private Sub Cmd_Print_Current_Rec_Click()
              On Error GoTo Err_Cmd_Print_Current_Rec_Click

              Dim strDocName As String
              Dim strFilter As String

              DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70 ‘Save record

              strDocName = “Invoice”
              strFilter = “tbl_Invoices.InvID = Forms!frm_Student!InvID”

              DoCmd.OpenReport strDocName, acViewNormal, , strFilter

              Exit_Cmd_Print_Current_Rec_Click:
              Exit Sub

              Err_Cmd_Print_Current_Rec_Click:
              MsgBox Err.Description
              Resume Exit_Cmd_Print_Current_Rec_Click

              End Sub


              [/indent]With this ….

              Private Sub Cmd_Print_Current_Rec_Click()
              On Error GoTo Err_Cmd_Print_Current_Rec_Click

              Dim strDocName As String
              Dim stLinkCriteria As String

              DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70 ‘Save record

              strDocName = “Invoice”
              stLinkCriteria = “[InvID]=” & Me![InvID]

              DoCmd.OpenReport stDocName, acPreview, , stLinkCriteria

              Exit_Cmd_Print_Current_Rec_Click:
              Exit Sub

              Err_Cmd_Print_Current_Rec_Click:
              MsgBox Err.Description
              Resume Exit_Cmd_Print_Current_Rec_Click

              End Sub

              Then cross your fingers . wink

            • #524303

              Ummmmmm….I tried it, but it didn’t work. It said that it can’t find InvID. I have that on my form, but InvID is actually on the form in a subform. Does that make any difference?

              Jennifer

            • #524304

              Okay .. try changing this line [indent]


              stLinkCriteria = “[InvID]=” & Forms!frm_Student!InvID


              [/indent] Crossing my fingers …

            • #524306

              I tried it and it gave me a message that it couldn’t find my “frm_Student”, so I changed it to just “Student” because that is what it is called under my forms tab. Then it gave me the same message as before that it couldn’t find InvID.

              Jennifer dizzy

            • #524318

              I found something about using a “CurrentRecord” phrase in the coding, but it doesn’t really show enough info for me to really know how to use it properly. Have you used this?

              Jennifer

            • #524434

              Jennifer sorry you’re having so much difficulty. I’ve been away not ignoring you. I think you’re very close. You’ve got to determine the Link. First, you are attempting to print a report, correct? If so, in the query underlying the report you do have a field InvID, correct? If that’s true, all you should need to do is locate InvID in the form. You have what sounds like a main form and two subforms. When you determine the name of the subform containing the InvID insert it in the stLinkCriteria line.

            • #524438

              Now I get a syntax error in this line:

              stLinkCriteria = “[InvID]=” & Forms!Invoices Subform!InvID

              What did I do wrong? This is really driving me crazy!

              …okay, now I don’t get the syntax error, but now it can’t find the form “Invoices_Subform”. But I DO have a form called “Invoices Subform”(I noticed that it syntaxed because I had no “_” in there). Why can’t it find my subform?

              …okay. I fiddled with it some more. Now I actually got it to print my one invoice! Yeh, I’m doing the happy dance! But now, how do I get it just to print instead of preview it first?

              Jennifer

            • #524447

              Whoopee !!! joy
              Replace the phrase acPreview with acNormal

              I actually added the acPreview criteria on purpose to save you paper laugh since some of your attempts were printing all the invoices. Glad you got it going.

            • #524450

              Thanks, Brian! groovin

    • #527378

      So I would enter under criteria in the query design for InvID “=forms!frmInvoices!InvID”? Is that right? I’m a little confused.

      Jennifer

    Viewing 4 reply threads
    Reply To: Print ONE Invoice!

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: