Print a single record

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Robert

    Print a single record

    I have this set as the onclick event procedure for a command button on
    a form:

    Private Sub cmdPrintRecord_ Click()

    Dim strReportName As String
    Dim strCriteria As String

    strReportName = "rptPrintRecord "
    strCriteria = "[ID]='" & Me![ID] & "'"
    DoCmd.OpenRepor t strReportName, acViewPreview, , strCriteria

    End Sub

    to print (preview) the record currently "on-screen" and a report named
    "rptPrintRecord " yet I am having an error returned:

    Data type mismatch in criteria expression

    Can anyone help?

    Thanks

    Bob
  • Allen Browne

    #2
    Re: Print a single record

    What is the data type if the ID field?

    If is is a Number type field (not a Text type field), drop the extra quotes,
    i.e.:
    strCriteria = "[ID] = " & Me![ID]


    --
    Allen Browne - Microsoft MVP. Perth, Western Australia.
    Tips for Access users - http://allenbrowne.com/tips.html
    Reply to group, rather than allenbrowne at mvps dot org.

    "Robert" <showopeningscr een@yahoo.co.uk > wrote in message
    news:95c0dd51.0 311240547.3085f 3c3@posting.goo gle.com...[color=blue]
    > I have this set as the onclick event procedure for a command button on
    > a form:
    >
    > Private Sub cmdPrintRecord_ Click()
    >
    > Dim strReportName As String
    > Dim strCriteria As String
    >
    > strReportName = "rptPrintRecord "
    > strCriteria = "[ID]='" & Me![ID] & "'"
    > DoCmd.OpenRepor t strReportName, acViewPreview, , strCriteria
    >
    > End Sub
    >
    > to print (preview) the record currently "on-screen" and a report named
    > "rptPrintRecord " yet I am having an error returned:
    >
    > Data type mismatch in criteria expression
    >
    > Can anyone help?
    >
    > Thanks
    >
    > Bob[/color]


    Comment

    • Tom van Stiphout

      #3
      Re: Print a single record

      On 24 Nov 2003 05:47:10 -0800, showopeningscre en@yahoo.co.uk (Robert)
      wrote:

      This could happen if ID is a numeric field. Remove the wrappijng
      single quotes.

      -Tom.


      [color=blue]
      >I have this set as the onclick event procedure for a command button on
      >a form:
      >
      >Private Sub cmdPrintRecord_ Click()
      >
      > Dim strReportName As String
      > Dim strCriteria As String
      >
      > strReportName = "rptPrintRecord "
      > strCriteria = "[ID]='" & Me![ID] & "'"
      > DoCmd.OpenRepor t strReportName, acViewPreview, , strCriteria
      >
      >End Sub
      >
      >to print (preview) the record currently "on-screen" and a report named
      >"rptPrintRecor d" yet I am having an error returned:
      >
      >Data type mismatch in criteria expression
      >
      >Can anyone help?
      >
      >Thanks
      >
      >Bob[/color]

      Comment

      • Keith Wilby

        #4
        Re: Print a single record

        showopeningscre en@yahoo.co.uk (Robert) wrote:
        [color=blue]
        > I have this set as the onclick event procedure for a command button on
        > a form:
        >
        > Private Sub cmdPrintRecord_ Click()
        >
        > Dim strReportName As String
        > Dim strCriteria As String
        >
        > strReportName = "rptPrintRecord "
        > strCriteria = "[ID]='" & Me![ID] & "'"
        > DoCmd.OpenRepor t strReportName, acViewPreview, , strCriteria
        >
        > End Sub
        >
        > to print (preview) the record currently "on-screen" and a report named
        > "rptPrintRecord " yet I am having an error returned:
        >
        > Data type mismatch in criteria expression
        >
        > Can anyone help?
        >
        > Thanks
        >
        > Bob
        >[/color]

        If ID is a number then lose the quotes around the control name:

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

        HTH - Keith.

        Comment

        • paii, Ron

          #5
          Re: Print a single record

          If [ID] is a string use "" 2 double quotes not ' single.
          Me![ID] cannot be NULL

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

          "Robert" <showopeningscr een@yahoo.co.uk > wrote in message
          news:95c0dd51.0 311240547.3085f 3c3@posting.goo gle.com...[color=blue]
          > I have this set as the onclick event procedure for a command button on
          > a form:
          >
          > Private Sub cmdPrintRecord_ Click()
          >
          > Dim strReportName As String
          > Dim strCriteria As String
          >
          > strReportName = "rptPrintRecord "
          > strCriteria = "[ID]='" & Me![ID] & "'"
          > DoCmd.OpenRepor t strReportName, acViewPreview, , strCriteria
          >
          > End Sub
          >
          > to print (preview) the record currently "on-screen" and a report named
          > "rptPrintRecord " yet I am having an error returned:
          >
          > Data type mismatch in criteria expression
          >
          > Can anyone help?
          >
          > Thanks
          >
          > Bob[/color]


          Comment

          • Robert

            #6
            Re: Print a single record

            I've got it.

            Thanks to you all for taking the time and trouble to post advice.
            Bob

            Comment

            Working...