I'm having trouble retrieving records with one of my unbound text boxes.
cboCountryId is one of the unbound combo boxes on the main form.
The main form has a subform on it, which displays data based on criteria selected in the unbound combo boxes on the main form.
All the unbound combo boxes on the main form work great for the SQL. Only the cboCountryId does not work.
The country table contains the following fields:
CountryId (Primary Key - Text): CA
Country (Text): Canada
tblCountry is bound to tblShipments:
CountryId (Foreign Key - Text): CA
Here are the two bits of code that are causing me grief:
If Not IsNull(Me.cboCountryId) Then
If Not strSQLFilter = "" Then
strSQLFilter = strSQLFilter & " AND tblShipments.CountryID = " & [cboCountryId]
Else
strSQLFilter = strSQLFilter & " tblShipments.CountryID = " & [cboCountryId]
End If
End If
If strSQLFilter = "" Then
strSQL = "SELECT DISTINCTROW tblShipments.ShipmentID, tblProduct.Description AS Product, tblVessels.Description AS Vessel, tblShipments.SAPReleaseNum, tblCustomer.Description AS Customer, tblSource.Description AS Source, tblPort.Description AS Port, tblShipments.[CountryID] AS Country, tblShipments.Volume, tblShipments.SellingPrice AS Price FROM (((((((tblShipments LEFT JOIN tblCustomer ON tblShipments.CustomerID = tblCustomer.CustomerId) LEFT JOIN tblPort ON tblShipments.PortID = tblPort.PortID) LEFT JOIN tblProduct ON tblShipments.ProductID = tblProduct.ProductID) LEFT JOIN tblSeller ON tblShipments.SellerID = tblSeller.SellerID) LEFT JOIN tblSource ON tblShipments.SourceID = tblSource.SourceID) LEFT JOIN tblVessels ON tblShipments.VesselID = tblVessels.VesselID) LEFT JOIN tblTransactionType ON tblShipments.TransTypeID = tblTransactionType.TransTypeID)" & _
"ORDER BY tblShipments.VesselID;"
Else
strSQLFilter = strSQLFilter
strSQL = "SELECT DISTINCTROW tblShipments.ShipmentID, tblProduct.Description AS Product, tblVessels.Description AS Vessel, tblShipments.SAPReleaseNum, tblCustomer.Description AS Customer, tblSource.Description AS Source, tblPort.Description AS Port, tblShipments.[CountryID] AS Country, tblShipments.Volume, tblShipments.SellingPrice AS Price FROM (((((((tblShipments LEFT JOIN tblCustomer ON tblShipments.CustomerID = tblCustomer.CustomerId) LEFT JOIN tblPort ON tblShipments.PortID = tblPort.PortID) LEFT JOIN tblProduct ON tblShipments.ProductID = tblProduct.ProductID) LEFT JOIN tblSeller ON tblShipments.SellerID = tblSeller.SellerID) LEFT JOIN tblSource ON tblShipments.SourceID = tblSource.SourceID) LEFT JOIN tblVessels ON tblShipments.VesselID = tblVessels.VesselID) LEFT JOIN tblTransactionType ON tblShipments.TransTypeID = tblTransactionType.TransTypeID)" & _
" WHERE " & strSQLFilter & "ORDER BY tblShipments.VesselID;"
End If
Forms!frmMain!subfrmMain.Form.RecordSource = strSQL
Forms!frmMain!subfrmMain.Form.Requery
NOTE: As soon as I pick an item from cboCountryId as criteria, no records are retrieved, but I know that there should be matching records.
I am obviously missing something? Any ideas?
The only difference between the cboCountryId combo box and all the other ones, is that the primary key is a text field.
Looking forward to some help with this one.......THANKS!
cboCountryId is one of the unbound combo boxes on the main form.
The main form has a subform on it, which displays data based on criteria selected in the unbound combo boxes on the main form.
All the unbound combo boxes on the main form work great for the SQL. Only the cboCountryId does not work.
The country table contains the following fields:
CountryId (Primary Key - Text): CA
Country (Text): Canada
tblCountry is bound to tblShipments:
CountryId (Foreign Key - Text): CA
Here are the two bits of code that are causing me grief:
If Not IsNull(Me.cboCountryId) Then
If Not strSQLFilter = "" Then
strSQLFilter = strSQLFilter & " AND tblShipments.CountryID = " & [cboCountryId]
Else
strSQLFilter = strSQLFilter & " tblShipments.CountryID = " & [cboCountryId]
End If
End If
If strSQLFilter = "" Then
strSQL = "SELECT DISTINCTROW tblShipments.ShipmentID, tblProduct.Description AS Product, tblVessels.Description AS Vessel, tblShipments.SAPReleaseNum, tblCustomer.Description AS Customer, tblSource.Description AS Source, tblPort.Description AS Port, tblShipments.[CountryID] AS Country, tblShipments.Volume, tblShipments.SellingPrice AS Price FROM (((((((tblShipments LEFT JOIN tblCustomer ON tblShipments.CustomerID = tblCustomer.CustomerId) LEFT JOIN tblPort ON tblShipments.PortID = tblPort.PortID) LEFT JOIN tblProduct ON tblShipments.ProductID = tblProduct.ProductID) LEFT JOIN tblSeller ON tblShipments.SellerID = tblSeller.SellerID) LEFT JOIN tblSource ON tblShipments.SourceID = tblSource.SourceID) LEFT JOIN tblVessels ON tblShipments.VesselID = tblVessels.VesselID) LEFT JOIN tblTransactionType ON tblShipments.TransTypeID = tblTransactionType.TransTypeID)" & _
"ORDER BY tblShipments.VesselID;"
Else
strSQLFilter = strSQLFilter
strSQL = "SELECT DISTINCTROW tblShipments.ShipmentID, tblProduct.Description AS Product, tblVessels.Description AS Vessel, tblShipments.SAPReleaseNum, tblCustomer.Description AS Customer, tblSource.Description AS Source, tblPort.Description AS Port, tblShipments.[CountryID] AS Country, tblShipments.Volume, tblShipments.SellingPrice AS Price FROM (((((((tblShipments LEFT JOIN tblCustomer ON tblShipments.CustomerID = tblCustomer.CustomerId) LEFT JOIN tblPort ON tblShipments.PortID = tblPort.PortID) LEFT JOIN tblProduct ON tblShipments.ProductID = tblProduct.ProductID) LEFT JOIN tblSeller ON tblShipments.SellerID = tblSeller.SellerID) LEFT JOIN tblSource ON tblShipments.SourceID = tblSource.SourceID) LEFT JOIN tblVessels ON tblShipments.VesselID = tblVessels.VesselID) LEFT JOIN tblTransactionType ON tblShipments.TransTypeID = tblTransactionType.TransTypeID)" & _
" WHERE " & strSQLFilter & "ORDER BY tblShipments.VesselID;"
End If
Forms!frmMain!subfrmMain.Form.RecordSource = strSQL
Forms!frmMain!subfrmMain.Form.Requery
NOTE: As soon as I pick an item from cboCountryId as criteria, no records are retrieved, but I know that there should be matching records.
I am obviously missing something? Any ideas?
The only difference between the cboCountryId combo box and all the other ones, is that the primary key is a text field.
Looking forward to some help with this one.......THANKS!