Results 1 to 2 of 2
  1. #1
    Join Date
    Aug 2002
    Posts
    2

    Unanswered: .OpenReport Problems (where condition)

    I am usually a SQL guy so my VB is not all that great. I am trying to print only one page of a report, but what is happening is that all pages of the report are printing. I am sure this is due to a faulty where condition, but I am unfamiliar with how this works in VB

    I am starting with a recordset from a query (qrySortToPrint) that is sorted like this:

    NAME, COUNTY, KEYPROV, MEM, MEASCODE, FORMNO

    The reports I need are different based on MEASCODE. (rptAIS, rptBBT, etc.)

    So what I need to do is check the MEASCODE value in the current record, open the corresponding report, and print ONLY the page of the report that has the same FORMNO as the current record in the recordset, then move to the next record and do the same. What happens is that it does open the correct report for that first record, but prints out ALL of the pages that have that MEASCODE. Here is my code... please tell me where I am screwing up.

    Private Sub Printing()
    Dim rs As DAO.Recordset
    Dim strcrit As String
    Dim strFormNo As String

    Set rs = CurrentDb.OpenRecordset("qrySortToPrint")
    rs.MoveFirst

    Do While Not rs.EOF
    strcrit = rs("MEASCODE")
    strFormNo = rs("formno")

    If strcrit = "AIS" Then
    DoCmd.OpenReport "rptAIS", , , FORMNO = strFormNo
    End If
    If strcrit = "BBT" Then
    DoCmd.OpenReport "rptBBT", , , FORMNO = strFormNo
    End If
    rs.MoveNext
    Loop

  2. #2
    Join Date
    Jul 2002
    Location
    Romania
    Posts
    122
    DoCmd.OpenReport "rptAIS", , , "FORMNO = '" & strFormNo & "'"

    will do if strFormNo is a string. If it's numeric:

    DoCmd.OpenReport "rptAIS", , , "FORMNO = " & strFormNo

    Regards,

    dan

Posting Permissions

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