Results 1 to 6 of 6
  1. #1
    2 Star Lounger
    Join Date
    May 2001
    Location
    Maryland, USA
    Posts
    105
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Printing a Report from a Form

    I used the example below from the Microsoft site to set up a button on a form to print out a single record of the data on it's report. Everything worked fine. Then I decided to use an autonumber for what this example uses as CustomerID. Now I keep getting a message that says:

    Runtime error '3464':
    Data type mismatch in criteria expression

    I went back and changed the field to a text field and everything worked fine, except, of course, if I do it this way it won't generate the unique number I need for each new record.

    Is there some reason it doesn't like the AutoNumber generated field? Is there a way around it?

    Thanks,
    Eric


    Private Sub cmdPrintRecord_Click()

    Dim strReportName As String
    Dim strCriteria As String

    strReportName = "rptPrintRecord"
    strCriteria = "[CustomerID]='" & Me![CustomerID] & "'"
    DoCmd.OpenReport strReportName, acViewPreview, , strCriteria

    End Sub

  2. #2
    3 Star Lounger
    Join Date
    Feb 2001
    Location
    NYC,USA,Earth
    Posts
    273
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Printing a Report from a Form

    When using strings in where clauses the string value must be surrounded by quotes. When using numbers (such as an autonumber which is a long integer) quotes are not required. Replace your strCriteria line:

    strCriteria = "[CustomerID]='" & Me![CustomerID] & "'"

    With the following:

    strCriteria = "[CustomerID]=" & Me![CustomerID]

    You get the mismatch error because using the quotes Access tries to treat the autonumber as a string, which it is not.

  3. #3
    2 Star Lounger
    Join Date
    May 2001
    Location
    Maryland, USA
    Posts
    105
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Printing a Report from a Form

    Thanks for the quick response. I tried that and now am getting:

    Run-time error '3075':
    Syntax error in string in query expression '([CustomerID]='3)'.

    3 is the autonumber of the record. The DoCmd.OpenReport line is highlighted.

    Eric

  4. #4
    3 Star Lounger
    Join Date
    Feb 2001
    Location
    NYC,USA,Earth
    Posts
    273
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Printing a Report from a Form

    <hr>Run-time error '3075':
    Syntax error in string in query expression '([CustomerID]='3)'.<hr>

    Notice that there's a single quote before the 3 above. Look closely at my first post and copy and paste the expression in your code procedure, changing the name of the control object to your own.

  5. #5
    2 Star Lounger
    Join Date
    May 2001
    Location
    Maryland, USA
    Posts
    105
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Printing a Report from a Form

    I've done that. Now it doesn't give me an error, but it is also showing every record in the report. What I'm trying to do is for it to show me just the current record that I was viewing on the form.

    Thanks for your help.

    Eric

  6. #6
    2 Star Lounger
    Join Date
    May 2001
    Location
    Maryland, USA
    Posts
    105
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Printing a Report from a Form

    Oops! My mistake. It is working right. I had been experimenting with doing an append query to add records and unintentionally added duplicate records and the indexed property was set to accept duplicates.

    Thanks a lot for your help!

    Eric

Posting Permissions

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