Results 1 to 2 of 2
  1. #1
    Compufreak is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Jul 2012
    Posts
    70

    feedback on query written

    Code:
    Private Sub Run_Report_Click()
    Dim strSQL As String
        
        strSQL = "SELECT  Cluster_Dept.ID, Cluster_Dept.Cluster_ID, Cluster_Dept.Dept_ID, Clusters.Cluster_Desc, Department.Dept_Desc, " & _
                    "Source.Day_Month_Year, Source.Original_Source, Source.Headline, Source.Issue, Source.Analysis, Source.Action " & _
                    "FROM Source INNER JOIN (Department INNER JOIN (Clusters INNER JOIN Cluster_Dept ON Clusters.Cluster_ID " & _
                    "= Cluster_Dept.Cluster_ID) ON Department.Dept_ID = Cluster_Dept.Dept_ID) ON Source.ID = Cluster_Dept.ID"
    
        
        
        If IsNull(Combo1.Value) And IsNull([StartDate]) And IsNull([EndDate]) And IsNull([Search]) And IsNull(Combo53.Value) Then
                'run report without any condition
               strSQL = strSQL & ";"
           
             Else
                If ((Combo1.Value <> " ") And IsNull([StartDate]) And IsNull([EndDate])) And (Combo53.Value <> " ") Then
                            'run report by category
                            'strSQL = strSQL & " " & "WHERE [Clusters].Cluster_Desc =" & Chr(34) & [Combo1] & Chr(34) & " and " & [Source].Analysis = "& Chr(34) & [Combo53] & Chr(34)" & ";"
                             strSQL = strSQL & " " & "WHERE [Clusters].Cluster_Desc =" & Chr(34) & [Combo1] & Chr(34) & " and [Source].Analysis = " & Chr(34) & [Combo53] & Chr(34) & ";"
             Else
                         If ((Combo1.Value <> " ") And IsNull([StartDate]) And IsNull([EndDate])) And IsNull(Combo53.Value) Then
                            'run report by category
                            'strSQL = strSQL & " " & "WHERE [Clusters].Cluster_Desc =" & Chr(34) & [Combo1] & Chr(34) & " and " & [Source].Analysis = "& Chr(34) & [Combo53] & Chr(34)" & ";"
                             strSQL = strSQL & " " & "WHERE [Clusters].Cluster_Desc =" & Chr(34) & [Combo1] & Chr(34) & ";"
             Else
                    If IsNull(Combo1.Value) And (([StartDate] <> " ") Or ([EndDate] <> " ")) And (Combo53.Value <> " ") Then
                      'run report by date recieved"
                       strSQL = strSQL & " " & "WHERE [Day_Month_Year] Between #" & [StartDate] & "# AND #" & [EndDate] & "#" & " and [Source].Analysis = " & Chr(34) & [Combo53] & Chr(34)
             Else
                    If IsNull(Combo1.Value) And (([StartDate] <> " ") Or ([EndDate] <> " ")) And IsNull(Combo53.Value) Then
                      'run report by date recieved"
                       strSQL = strSQL & " " & "WHERE [Day_Month_Year] Between #" & [StartDate] & "# AND #" & [EndDate] & "#"
             Else
             
                       If (Combo1.Value <> " ") And (([StartDate] <> " ") Or ([EndDate] <> " ")) And (Combo53.Value <> " ") Then
                        strSQL = strSQL & " " & "WHERE Source.Day_Month_Year Between #" & [StartDate] & "# AND #" & [EndDate] & "# AND [Clusters].Cluster_Desc =" & Chr(34) & [Combo1] & Chr(34) & " and [Source].Analysis = " & Chr(34) & [Combo53] & Chr(34) & ";"
                        parSelection = [Combo1] & ";" & "Day_Month_Year:" & [StartDate] & "-" & [EndDate]
            Else
                       If (Combo1.Value <> " ") And (([StartDate] <> " ") Or ([EndDate] <> " ")) And IsNull(Combo53.Value) Then
                        strSQL = strSQL & " " & "WHERE Source.Day_Month_Year Between #" & [StartDate] & "# AND #" & [EndDate] & "# AND [Clusters].Cluster_Desc =" & Chr(34) & [Combo1] & Chr(34) & ";"
                        parSelection = [Combo1] & ";" & "Day_Month_Year:" & [StartDate] & "-" & [EndDate]
              Else
                            If (([Search] <> " ")) Then
                            strSQL = strSQL & " " & "WHERE Source.Headline Like" & Chr(34) & "*" & [Search] & "*" & Chr(34)
                            End If
                       End If
                    End If
                End If
                End If
                End If
                End If
        End If
      '   Assign SQL code to query that the entry form uses
                 CurrentDb.QueryDefs("Search_by_Clusters and date").SQL = strSQL
                 
                'Open the report
                DoCmd.OpenReport "Search_by_Clusters and date", acViewReport
    End Sub




    i would like to know if there is anything wrong with my code as when i am using it in access runtime , it kicks me out when i enter conditions and click the run report button. Please help

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,601
    Step debug. Refer to link at bottom of my post for debug techniques.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Replies: 2
    Last Post: 07-19-2011, 04:28 PM
  2. Close Form, No Changes Written
    By shelzmike in forum Access
    Replies: 18
    Last Post: 06-30-2011, 10:36 PM
  3. Feedback for Access 2010
    By Michele Keck in forum Access
    Replies: 1
    Last Post: 10-01-2010, 11:47 AM
  4. OLE object not written to database
    By Jean-Louis Leroy in forum Forms
    Replies: 0
    Last Post: 06-08-2010, 02:08 AM
  5. Replies: 1
    Last Post: 01-30-2010, 04:45 PM

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