Results 1 to 4 of 4
  1. #1
    chuyee17 is offline Novice
    Windows Vista Access 2007
    Join Date
    Oct 2011
    Posts
    2

    Get combo box value to generate report


    i have two combo box, one is cboMonth and one is cboYear. i am trying to get the values from these 2 combo box, and used the value to generate report. however, when i click the btnPrintSummary button, system keep prompting me to enter parameter value. do i did something wrong? pls assist, thx.


    Code:
    Private Sub btnPrintSummary_Click()
    
        Dim stDocName As String
        Dim stWhere As String
        Dim blnTrim As Boolean
        
            If Not IsNull(Me.cboMonth) Then
                stWhere = "[Slip_Month]=" & Me.cboMonth & " And "
                blnTrim = True
            End If
    
            If Not IsNull(Me.cboYear) Then
                stWhere = stWhere & "[Slip_Year]=" & Me.cboYear
                blnTrim = True
            End If
      
            If blnTrim Then
                stWhere = Left(stWhere, Len(stWhere) - 5)
            End If
            
           
            stDocName = "RptSalarySummary"
            DoCmd.OpenReport stDocName, acPreview, , stWhere
    
        Exit Sub
    
    
    'DoCmd.OpenQuery "qrySalarySummary", acViewNormal
    
    End Sub

  2. #2
    ssanfu is offline Master of Nothing
    Windows 2K Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Code:
    Private Sub btnPrintSummary_Click()
        Dim stDocName As String
        Dim stWhere As String
        Dim blnTrim As Boolean
        
            If Not IsNull(Me.cboMonth) Then
                stWhere = "[Slip_Month]=" & Me.cboMonth & " And "
                blnTrim = True
            End If
            If Not IsNull(Me.cboYear) Then
                stWhere = stWhere & "[Slip_Year]=" & Me.cboYear
                blnTrim = True
            End If
      
            If blnTrim Then
                stWhere = Left(stWhere, Len(stWhere) - 5)
            End If
           
    
            stDocName = "RptSalarySummary"
            DoCmd.OpenReport stDocName, acPreview, , stWhere
    
        Exit Sub
    
    
    'DoCmd.OpenQuery "qrySalarySummary", acViewNormal
    
    End Sub
    Did you set a breakpoint, 'message box' or 'Debug.Print' to see what the value of stWhere was just before the report open statement?

    It looks to me that you are cutting off the year because "blnTrim" is TRUE in the check to see if cboYear is NULL.

    Try this:
    Code:
    Private Sub btnPrintSummary_Click()
    
        Dim stDocName As String
        Dim stWhere As String
        Dim blnTrim As Boolean
        
            If Not IsNull(Me.cboMonth) Then
                stWhere = "[Slip_Month]=" & Me.cboMonth & " And "
                blnTrim = True
            End If
    
            If Not IsNull(Me.cboYear) Then
                stWhere = stWhere & "[Slip_Year]=" & Me.cboYear
                blnTrim = FALSE
            End If
      
            If blnTrim Then
                stWhere = Left(stWhere, Len(stWhere) - 5)
            End If
            
          ' remove or comment out when done troubleshooting
           DEBUG.PRINT stWhere
            
            stDocName = "RptSalarySummary"
            DoCmd.OpenReport stDocName, acPreview, , stWhere
    
    
    End Sub

  3. #3
    chuyee17 is offline Novice
    Windows Vista Access 2007
    Join Date
    Oct 2011
    Posts
    2
    i tried the code. but still prompt me to enter parameter value. and after that, prompt me run time 3071 error, this expression is type incorrectly or query is too complex.

    pls assist.

    Code:
    Private Sub btnPrintSummary_Click()
        Dim stDocName As String
        Dim stWhere As String
        Dim blnTrim As Boolean
        
            If Not IsNull(Me.cboMonth) Then
                stWhere = "[Slip_Month]=" & Me.cboMonth & " And "
                blnTrim = True
            End If
    
            If Not IsNull(Me.cboYear) Then
                stWhere = stWhere & "[Slip_Year]=" & Me.cboYear
                blnTrim = FALSE
            End If
      
            If blnTrim Then
                stWhere = Left(stWhere, Len(stWhere) - 5)
            End If
            
          ' remove or comment out when done troubleshooting
           DEBUG.PRINT stWhere
            
            stDocName = "RptSalarySummary"
            DoCmd.OpenReport stDocName, acPreview, , stWhere
    End Sub

  4. #4
    ssanfu is offline Master of Nothing
    Windows 2K Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Quote Originally Posted by chuyee17 View Post
    i tried the code. but still prompt me to enter parameter value. and after that, prompt me run time 3071 error, this expression is type incorrectly or query is too complex.

    pls assist.
    What was the result of the DEBUG print statement?

    What is the SQL of the query?

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

Similar Threads

  1. Replies: 9
    Last Post: 08-30-2011, 04:08 PM
  2. Query Won't Generate Report
    By italianfinancier in forum Queries
    Replies: 1
    Last Post: 06-02-2011, 03:48 PM
  3. Can a report execute generate a file
    By techexpressinc in forum Reports
    Replies: 7
    Last Post: 01-16-2010, 04:03 AM
  4. Pdf Report Generate from Access
    By ACHU in forum Reports
    Replies: 1
    Last Post: 10-29-2009, 07:49 AM
  5. using a Form with combo boxes to generate reports
    By mistervelasco in forum Access
    Replies: 2
    Last Post: 10-28-2009, 03:38 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