[FONT="]I have a database with multiple tables...[/FONT]
[FONT="] [/FONT]
[FONT="]ExpRecords is the main table.. There is another table called ExpDocsOut which is linked by a “AEC” reference number field.[/FONT]
[FONT="] [/FONT]
[FONT="]When the user sends the final paperwork to customer he completes a “Docs Out” entry. [/FONT]
[FONT="] [/FONT]
[FONT="]Im doing a listbox query which shows all of the documents that NEED to be sent to customer .. I am using SQL statement & specifying if docs out fields for a specific record are empty then include the record.. If docs out has been done it should be omitted from the list. Ideally what I need to be able to write is IF a docs out entry DOESN’T exist for that shipment include the record... How can I write that in my sql statement? Write now im using the [/FONT]
[FONT="] [/FONT]
[FONT="]“DocsOUT = "(((ExpDocsOut.BillOfLading)=false OR Isnull(Expdocsout.SentTracking)=true OR Isnull(Expdocsout.sentvia)=true OR Isnull(Expdocsout.senttracking)=true))" which isn’t including all records.. It omits the records in which no docs out has even been done...[/FONT]
[FONT="] [/FONT]
[FONT="] [/FONT]
[FONT="]Private Function DocumentationQuery()[/FONT]
[FONT="]Dim SQL As String[/FONT]
[FONT="]Dim SqlGroup As String[/FONT]
[FONT="]Dim SqlManager As String[/FONT]
[FONT="]Dim SqlAge As String[/FONT]
[FONT="]Dim DocsOUT As String[/FONT]
[FONT="] [/FONT]
[FONT="]DocsOUT = "(((ExpDocsOut.BillOfLading)=false OR Isnull(Expdocsout.SentTracking)=true OR Isnull(Expdocsout.sentvia)=true OR Isnull(Expdocsout.senttracking)=true))"[/FONT]
[FONT="] [/FONT]
[FONT="]'' Sets the criteria for SQL query for tracking group[/FONT]
[FONT="] Select Case (Me.ExpOBMQueryGroupCmbo)[/FONT]
[FONT="] Case "All Groups": SqlGroup = "(((ExpRecords.[Tracking Group]) <> [Forms]![ExpOutBoundManager]![ExpOBMQueryGroupCmbo]))"[/FONT]
[FONT="] Case Else: SqlGroup = "(((ExpRecords.[Tracking Group]) = [Forms]![ExpOutBoundManager]![ExpOBMQueryGroupCmbo]))"[/FONT]
[FONT="] End Select[/FONT]
[FONT="] [/FONT]
[FONT="]'' Sets the criteria for SQL query for Job Manager[/FONT]
[FONT="] Select Case (Me.ExpOBMQueryManagerCmbo)[/FONT]
[FONT="] Case "All Users": SqlManager = "(((ExpRecords.[Job Manager]) <> [Forms]![ExpOutBoundManager]![ExpOBMQueryManagerCmbo]))"[/FONT]
[FONT="] Case Else: SqlManager = "(((ExpRecords.[Job Manager]) = [Forms]![ExpOutBoundManager]![ExpOBMQueryManagerCmbo]))"[/FONT]
[FONT="] End Select[/FONT]
[FONT="] [/FONT]
[FONT="]'' Sets the criteria for SQL query for Shipment age[/FONT]
[FONT="] Select Case (Me.ExpOBMQueryAgeCmbo)[/FONT]
[FONT="] Case "Current 30 Days": SqlAge = "(((ExpBooking.[DateOfDeparture]) > Date() - 30))"[/FONT]
[FONT="] Case "Current 6 Months": SqlAge = "(((ExpBooking.[DateOfDeparture]) > Date() - 183))"[/FONT]
[FONT="] Case "Current Year": SqlAge = "(((ExpBooking.[DateOfDeparture]) > Date() - 365))"[/FONT]
[FONT="] Case "All Shipments": SqlAge = "(((ExpBooking.[DateOfDeparture]) <> Date()-0))"[/FONT]
[FONT="] End Select[/FONT]
[FONT="] [/FONT]
[FONT="] [/FONT]
[FONT="]'' Actual SQL query to display records for AES REQUIREMENTS using the users criteria from combo boxes.[/FONT]
[FONT="]SQL = "SELECT ExpRecords.AEC, ExpRecords.Shipper, ExpBooking.UltimateCarrierRef AS Booking, ExpRecords.[Aarid Service Type]," & _[/FONT]
[FONT="]" ExpBooking.PortOfLoading AS [Load Port], ExpBooking.PortOfUnloading AS [Unload Port],[ExpBooking].[Dateofarrival]-Date() as [Days Until Required], " & _[/FONT]
[FONT="]" ExpDocsOut.SentDate AS [Date Out], ExpDocsOut.SentTracking AS [Tracking Number]" & _[/FONT]
[FONT="]" FROM (ExpRecords INNER JOIN ExpBooking ON ExpRecords.AEC = ExpBooking.AEC) INNER JOIN ExpDocsOut ON ExpRecords.AEC = ExpDocsOut.aec " & _[/FONT]
[FONT="]" WHERE (" & SqlGroup & "AND" & SqlManager & "AND" & SqlAge & "AND" & DocsOUT & ")"[/FONT]
[FONT="] [/FONT]
[FONT="] [/FONT]
[FONT="] [/FONT]
[FONT="]'' Assign's the data to the list & sets format[/FONT]
[FONT="] [/FONT]
[FONT="] With ExpOBMlist[/FONT]
[FONT="] .RowSource = SQL[/FONT]
[FONT="] .BoundColumn = 1[/FONT]
[FONT="] .ColumnWidths = ColAEC[/FONT]
[FONT="] .ColumnCount = 7[/FONT]
[FONT="] .Requery[/FONT]
[FONT="] End With[/FONT]
[FONT="] [/FONT]
[FONT="] Call UpdateOBMQueryLbl[/FONT]
[FONT="] [/FONT]
[FONT="]ExpRecords is the main table.. There is another table called ExpDocsOut which is linked by a “AEC” reference number field.[/FONT]
[FONT="] [/FONT]
[FONT="]When the user sends the final paperwork to customer he completes a “Docs Out” entry. [/FONT]
[FONT="] [/FONT]
[FONT="]Im doing a listbox query which shows all of the documents that NEED to be sent to customer .. I am using SQL statement & specifying if docs out fields for a specific record are empty then include the record.. If docs out has been done it should be omitted from the list. Ideally what I need to be able to write is IF a docs out entry DOESN’T exist for that shipment include the record... How can I write that in my sql statement? Write now im using the [/FONT]
[FONT="] [/FONT]
[FONT="]“DocsOUT = "(((ExpDocsOut.BillOfLading)=false OR Isnull(Expdocsout.SentTracking)=true OR Isnull(Expdocsout.sentvia)=true OR Isnull(Expdocsout.senttracking)=true))" which isn’t including all records.. It omits the records in which no docs out has even been done...[/FONT]
[FONT="] [/FONT]
[FONT="] [/FONT]
[FONT="]Private Function DocumentationQuery()[/FONT]
[FONT="]Dim SQL As String[/FONT]
[FONT="]Dim SqlGroup As String[/FONT]
[FONT="]Dim SqlManager As String[/FONT]
[FONT="]Dim SqlAge As String[/FONT]
[FONT="]Dim DocsOUT As String[/FONT]
[FONT="] [/FONT]
[FONT="]DocsOUT = "(((ExpDocsOut.BillOfLading)=false OR Isnull(Expdocsout.SentTracking)=true OR Isnull(Expdocsout.sentvia)=true OR Isnull(Expdocsout.senttracking)=true))"[/FONT]
[FONT="] [/FONT]
[FONT="]'' Sets the criteria for SQL query for tracking group[/FONT]
[FONT="] Select Case (Me.ExpOBMQueryGroupCmbo)[/FONT]
[FONT="] Case "All Groups": SqlGroup = "(((ExpRecords.[Tracking Group]) <> [Forms]![ExpOutBoundManager]![ExpOBMQueryGroupCmbo]))"[/FONT]
[FONT="] Case Else: SqlGroup = "(((ExpRecords.[Tracking Group]) = [Forms]![ExpOutBoundManager]![ExpOBMQueryGroupCmbo]))"[/FONT]
[FONT="] End Select[/FONT]
[FONT="] [/FONT]
[FONT="]'' Sets the criteria for SQL query for Job Manager[/FONT]
[FONT="] Select Case (Me.ExpOBMQueryManagerCmbo)[/FONT]
[FONT="] Case "All Users": SqlManager = "(((ExpRecords.[Job Manager]) <> [Forms]![ExpOutBoundManager]![ExpOBMQueryManagerCmbo]))"[/FONT]
[FONT="] Case Else: SqlManager = "(((ExpRecords.[Job Manager]) = [Forms]![ExpOutBoundManager]![ExpOBMQueryManagerCmbo]))"[/FONT]
[FONT="] End Select[/FONT]
[FONT="] [/FONT]
[FONT="]'' Sets the criteria for SQL query for Shipment age[/FONT]
[FONT="] Select Case (Me.ExpOBMQueryAgeCmbo)[/FONT]
[FONT="] Case "Current 30 Days": SqlAge = "(((ExpBooking.[DateOfDeparture]) > Date() - 30))"[/FONT]
[FONT="] Case "Current 6 Months": SqlAge = "(((ExpBooking.[DateOfDeparture]) > Date() - 183))"[/FONT]
[FONT="] Case "Current Year": SqlAge = "(((ExpBooking.[DateOfDeparture]) > Date() - 365))"[/FONT]
[FONT="] Case "All Shipments": SqlAge = "(((ExpBooking.[DateOfDeparture]) <> Date()-0))"[/FONT]
[FONT="] End Select[/FONT]
[FONT="] [/FONT]
[FONT="] [/FONT]
[FONT="]'' Actual SQL query to display records for AES REQUIREMENTS using the users criteria from combo boxes.[/FONT]
[FONT="]SQL = "SELECT ExpRecords.AEC, ExpRecords.Shipper, ExpBooking.UltimateCarrierRef AS Booking, ExpRecords.[Aarid Service Type]," & _[/FONT]
[FONT="]" ExpBooking.PortOfLoading AS [Load Port], ExpBooking.PortOfUnloading AS [Unload Port],[ExpBooking].[Dateofarrival]-Date() as [Days Until Required], " & _[/FONT]
[FONT="]" ExpDocsOut.SentDate AS [Date Out], ExpDocsOut.SentTracking AS [Tracking Number]" & _[/FONT]
[FONT="]" FROM (ExpRecords INNER JOIN ExpBooking ON ExpRecords.AEC = ExpBooking.AEC) INNER JOIN ExpDocsOut ON ExpRecords.AEC = ExpDocsOut.aec " & _[/FONT]
[FONT="]" WHERE (" & SqlGroup & "AND" & SqlManager & "AND" & SqlAge & "AND" & DocsOUT & ")"[/FONT]
[FONT="] [/FONT]
[FONT="] [/FONT]
[FONT="] [/FONT]
[FONT="]'' Assign's the data to the list & sets format[/FONT]
[FONT="] [/FONT]
[FONT="] With ExpOBMlist[/FONT]
[FONT="] .RowSource = SQL[/FONT]
[FONT="] .BoundColumn = 1[/FONT]
[FONT="] .ColumnWidths = ColAEC[/FONT]
[FONT="] .ColumnCount = 7[/FONT]
[FONT="] .Requery[/FONT]
[FONT="] End With[/FONT]
[FONT="] [/FONT]
[FONT="] Call UpdateOBMQueryLbl[/FONT]