Results 1 to 10 of 10
  1. #1
    Join Date
    May 2006
    Posts
    25

    Red face Unanswered: Type Mismatch in print event procedure

    Hello,

    I am trying to set up a button on a form that will print several reports one after the other based on the current record of the form.

    I am having trouble setting the criteria.

    The database keeps track of our Participants, and each participant has a uniqe number (separate from the AutoNumber). The unique number is a Long Integer field called BookNumber.

    I have put in the following code:

    Code:
       lngCriteria = "[BookNumber] = " & Me![BookNumber]
       
       DoCmd.OpenReport strReportDiary, acViewPreview, , lngCriteria
       DoCmd.PrintOut acPages, 1, 1
    but when I click on the button that has this code attached to it, I get a Type Mismatch error.

    I get the feeling there is a syntax error somewhere and that I have missed a quote mark or something. Any ideas what I am doing wrong?

    Regards,
    Bronwyn

  2. #2
    Join Date
    May 2005
    Location
    Nevada, USA
    Posts
    2,888
    Provided Answers: 6
    How is lngCriteria declared? Its prefix implies Long, but you're putting a string into it.
    Paul

  3. #3
    Join Date
    May 2006
    Posts
    25
    Yay! I knew there would be someone out there who knew what they were doing. I have declared it like so:

    Dim lngCriteria as Long

    but I don't know how to refer to the BookNumber field in correct way.

  4. #4
    Join Date
    May 2003
    Location
    Dallas
    Posts
    817
    Provided Answers: 5
    try this
    dim myInt as integer ' or as a long
    myint = Me![booknumber]

    lngCriteria = "[BookNumber] = " & myint
    Dale Houston, TX

  5. #5
    Join Date
    May 2005
    Location
    Nevada, USA
    Posts
    2,888
    Provided Answers: 6
    No, the only thing you have to change is this:

    Dim lngCriteria as String
    Paul

  6. #6
    Join Date
    May 2003
    Location
    Dallas
    Posts
    817
    Provided Answers: 5
    either way "i think" would work
    Dale Houston, TX

  7. #7
    Join Date
    May 2005
    Location
    Nevada, USA
    Posts
    2,888
    Provided Answers: 6
    If lngCriteria is declared as integer, your way will still error:

    lngCriteria = "[BookNumber] = " & myint
    Paul

  8. #8
    Join Date
    Feb 2004
    Location
    Chicago, IL
    Posts
    1,312
    I would also suggest changing your variable to strCriteria, otherwise you may confuse anyone that is looking at your code.

  9. #9
    Join Date
    May 2006
    Posts
    25

    Thanks everyone

    You were right, I just needed to change the variable to a string. So in the end I had the following:

    Dim strCriteria as String

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

    ...and that worked fine. Thanks for all your suggestions!

  10. #10
    Join Date
    May 2003
    Location
    Dallas
    Posts
    817
    Provided Answers: 5
    Dim strCriteria as String

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

    does work

    but if booknumber is an integer and you
    dim myint as integer
    me!bookmark = myint

    wheather you define lngcriteria as a string and then paas the vaiable or define myint as integer to match the data type of booknumber (which I assumed was a number) both methods work
    Dale Houston, TX

Posting Permissions

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