Results 1 to 4 of 4
  1. #1
    Join Date
    Jan 2009
    Posts
    9

    Unanswered: Print Report Based on On screen form

    Dont suppose you know how to fix this ..

    I was given the code by a classmate. Works on his.


    Code:
    Dim strReportName As String
    Dim strCriteria As String

    DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70

    If NewRecord Then
    MsgBox "This record contains no data. Please select a record to print or Save this record." _
    , vbInformation, "Invalid Action"
    Exit Sub
    Else
    strReportName = "printtest"
    strCriteria = "[Product Number]= " & Me![Product Number]


    DoCmd.OpenReport strReportName, acNormal, , strCriteria

    End If
    Print report based on info on screen (at least it should)

    But dont work on mine, I get a Runtime error.

    Any ideas?

    Thanks in advance!

  2. #2
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    What error are you receiving?

    What is the Datatype of [Product Number]?
    Hope this helps!

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

    All posts/responses based on Access 2003/2007

  3. #3
    Join Date
    Jan 2009
    Posts
    9
    Runtime Error, Type mismatch.

    Code:
    DoCmd.OpenReport strReportName, acNormal, , strCriteria
    Seems to be the problem, how I dont know

    EDIT: If any alternatives come up, ill give them a go. In a nutshell, use a Form field as a Query criteria.

  4. #4
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    You didn't answer my second question "What is the Datatype of [Product Number]?" but I'm going to guess, based on the error reported, that [Product Number] is Datatype Text. If this is correct your syntax should be

    strCriteria = "[Product Number]= '" & Me![Product Number] & "'"

    The syntax changes depending on the Datatype. The classmate that it worked for probably had his/her Datatype set to Number, which is why it worked for them.

    BTW, the Datatype for a "number" should only be set to Numbers if the field will be used for math. Used as it is here, it should be Text, as you've apparently done.
    Hope this helps!

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

    All posts/responses based on Access 2003/2007

Posting Permissions

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