Results 1 to 5 of 5
  1. #1
    injanib is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Jan 2011
    Posts
    67

    Opening Report From Form

    Hi,

    I have a button on my form that is supposed to open three different reports based on their criteria. All three forms are are based on the same query.



    the reports are called : rptCompletionCertificate, rptAchievementCertificate, and rptDiploma

    The VBA on the Click Event property of of the button (actually label) is this.

    Private Sub lblPrintCertificate_Click()
    Dim strWhere As String
    Dim ctrl As Control
    Dim strReport As String

    strWhere = "[ID]=" & Me.txtRegistrationID
    Set ctrl = Me.txtCertificateType

    If Not IsNull(ctrl) Then
    Select Case ctrl
    Case "C. Certificate"
    strReport = "rptCompletionCertificate"
    Case "A. Certificate"
    strReport = "rptAchievementCertificate"
    Case "Diploma"
    strReport = "rptDiploma"

    End Select

    DoCmd.OpenReport strReport, acViewPreview, , strWhere
    End If
    End Sub

    What happens is when the case is true for "A. Certificate", the right report (rptAchievementCertificate) opens filtered in report view mode.

    But in the cases of "C. Certificate" and "Diploma", the right reports (rptCompletionCertificate and rptDiploma respectively) open filtered in print preview mode, but the rptAchievementCertificate also opens unfiltered in report view mode.

    I can't figure out why this is happening.

    Thanks in advance.

  2. #2
    ssanfu is offline Master of Nothing
    Windows 2K Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    I can't see anything wrong with the code, except I question the use of "Set ctrl ..." just to get a value from a text box. And Since you created a pointer, you should destroy it by the statement "Set ctrl = Nothing".

    This is how I would have written the code

    Code:
    Option Compare Database
    Option Explicit
    
    Private Sub lblPrintCertificate_Click()
       Dim strWhere As String
       Dim strReport As String
       Dim CertName As String
    
       'Dim ctrl As Control
    
       strWhere = "[ID]=" & Me.txtRegistrationID
       CertName = Me.txtCertificateType
       'Set ctrl = Me.txtCertificateType
    
       'If Not IsNull(ctrl) Then
       If Not IsNull(CertName) Then
          Select Case CertName
          Case "C. Certificate"
             strReport = "rptCompletionCertificate"
          Case "A. Certificate"
             strReport = "rptAchievementCertificate"
          Case "Diploma"
             strReport = "rptDiploma"
    
          End Select
    
          DoCmd.OpenReport strReport, acViewPreview, , strWhere
       End If
    End Sub

  3. #3
    injanib is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Jan 2011
    Posts
    67
    Thank you for the feedback. I tried the code the way you have written it. Unfortunately, it didn't make any difference.

    Any further suggestions?

  4. #4
    ssanfu is offline Master of Nothing
    Windows 2K Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Could be corruption. Delete the form, do a Compile and Repair, then close Access.

    Open the mdb and recreate the form.

  5. #5
    injanib is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Jan 2011
    Posts
    67
    I figured it out. The label was made a hyperlink to open rptAchievementCertificate. That is why it kept opening it regardless of the case.

    Thank you for you input.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Report not opening, just printing.
    By Desstro in forum Reports
    Replies: 3
    Last Post: 12-11-2010, 01:36 PM
  2. Report not opening to view
    By Desstro in forum Programming
    Replies: 4
    Last Post: 11-25-2010, 05:36 PM
  3. report opening problem
    By combine21 in forum Reports
    Replies: 1
    Last Post: 09-27-2010, 02:15 PM
  4. Opening a report
    By mwabbe in forum Access
    Replies: 3
    Last Post: 09-17-2010, 09:19 AM
  5. Opening one report for current form???
    By GEPC in forum Reports
    Replies: 1
    Last Post: 07-15-2010, 10:46 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums