Results 1 to 11 of 11
  1. #1
    Join Date
    May 2011
    Posts
    9

    Unanswered: Creating Invoices in Microsoft Database 2007

    Hi, can anyone tell me how to print out a specific invoice I created in the database? I have created a report format and link to the form which I use to create a new invoice, when I click print the current form, it print out all the invoices and not the specific invoice only. I had refer to the "Northwin" sample but still can't figure out how to do it.

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    use a form to select which invoice you want
    if you already have a form for incvoices, then I'd suggest placing a button on there which opens up the report and prints the current invoice

    place a command button on the form
    if you want to use the wizard to print a report. then do
    so

    switch to design mode on the form
    select the button, right click for build event, if promoted select code

    you need to make soem changes to the 'DoCmd.OpenReport' line
    set the report to acViewPreview if you want to preview the report BEFORE printing
    set a where condition
    if its numeric
    Code:
    "ID=12345678"
    if its string
    Code:
    "InvoiceNo = 'ABCDEFG'"
    if you didn't use the wizard
    Code:
    Private Sub MyButtonControl_Click()
    On Error GoTo Err_MyButtonControl_Click
    
        Dim stDocName As String
    
        stDocName = "MyReportName"
        DoCmd.OpenReport stDocName, acViewPreview, , "ID=12345678"
    
    Exit_MyButtonControl_Click:
        Exit Sub
    
    Err_MyButtonControl_Click:
        MsgBox Err.Description
        Resume Exit_Command7_Click
        
    End Sub
    replace the ID=12345678 with
    MyInvoiceNumber = MyInvocieNumberControl.value
    I'd rather be riding on the Tiger 800 or the Norton

  3. #3
    Join Date
    May 2011
    Posts
    9
    Thanks for your help, but sorry I still cant get the it right, please kindly check what's wrong with this:

    Private Sub Command13_Click()
    On Error GoTo Err_Command13_Click

    Dim stDocName As String

    stDocName = "rptInvoices/DO"
    DoCmd.OpenReport stDocName, acViewPreview, , "MyInvoiceNumber = MyInvocieNumberControl.value"

    Exit_Command13_Click:
    Exit Sub

    Err_Command13_Click:
    MsgBox Err.Description
    Resume Exit_Command13_Click

    End Sub

  4. #4
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    Is MyInvoiceNumber the actual name of the Field in your underlying Table that holds the data?

    Is MyInvocieNumberControl the actual name of the Control on your Form that holds this Value?

    If the answers are Yes and Yes, and if MyInvoiceNumber is defined as Text,

    Code:
    DoCmd.OpenReport stDocName, acViewPreview, , "MyInvoiceNumber = '" & Me.MyInvocieNumberControl & "'"



    If the answers are Yes and Yes, and if MyInvoiceNumber is defined as a Number,

    Code:
    DoCmd.OpenReport stDocName, acViewPreview, , "MyInvoiceNumber = " & Me.MyInvocieNumberControl


    Linq ;0)>
    Hope this helps!

    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  5. #5
    Join Date
    May 2011
    Posts
    9
    I still can't get it right, I am a self-learner so I am not quite sure I understand what you mean. I taken 3 photos of my database:

    1st photo (DSCN1606.JPG) show the design view of my form
    2nd photo (DSCN1607.JPG) show the "Print" button on the form, which when I click it should transfer the data on the current form to the report show in 3rd photo (DSCN1607.JPG) , so that I can print out the data for that particular invoice/DO.

    To do that, I suppose the code is like this:

    Private Sub Command13_Click()
    On Error GoTo Err_Command13_Click

    Dim stDocName As String

    stDocName = "rptInvoices/DO"
    DoCmd.OpenReport stDocName, acViewPreview, , "Invoice / DO No = " & Invoice / DONoControl & "'"

    Exit_Command13_Click:
    Exit Sub

    Err_Command13_Click:
    MsgBox Err.Description
    Resume Exit_Command13_Click

    Can show what's wrong with the code?
    Attached Thumbnails Attached Thumbnails DSCN1606.JPG   DSCN1607.JPG   DSCN1608.JPG  

  6. #6
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    You should never use Spaces or special characters in the names of Fields, Controls, etc, in Access. It leads to problems, such as you have here! When you do this, you need to enclose the names in Square Brackets so that the Access Gnomes know that you intended for these unrelated characters to be a single name! Assuming that Invoice / DO No is defined as Text, you're also missing a single Quotation Mark, so you'd need to use

    Code:
    DoCmd.OpenReport stDocName, acViewPreview, , "[Invoice / DO No] = '" & [Invoice / DONoControl] & "'"


    Linq ;0)>
    Hope this helps!

    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  7. #7
    Join Date
    May 2011
    Posts
    9
    Hi Linq, thanks for your explanation, I modified the code accordingly (field name: [Invoice/DO No]) but still can't get the report, it show an error message when I click print, please see the attached photo, please help me get it right.

  8. #8
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    Attached photo?
    Hope this helps!

    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  9. #9
    Join Date
    May 2011
    Posts
    9
    oh sorry, photos attached.
    Attached Thumbnails Attached Thumbnails DSCN1609.JPG   DSCN1610.JPG  

  10. #10
    Join Date
    May 2011
    Posts
    9
    Anyone can help?

  11. #11
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    so what do you think that error message is telling you

    check all controls and look for spelling mistakes / typos
    I'd rather be riding on the Tiger 800 or the Norton

Posting Permissions

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