Question : Need help with combobox not selecting the correct record

Hi Experts,

I have a form that is using a query as it's record source.
There is a combobox on it that I use to select which record I want to edit

Here is the query the form is using for it's record source.

SELECT FS_Vendor.VendorID, FS_Vendor.VendorName, FS_Vendor.VendorAddress1, FS_Vendor.VendorAddress2, FS_Vendor.VendorCity, FS_Vendor.VendorState, FS_Vendor.VendorZip, FS_Vendor.VendorCountry, FS_Vendor.VendorContactPhone, FS_Vendor.VendorContactFax, FS_Vendor.VendorContactEmail, tblVendor.Website, tblVendor.AccountNumber, tblVendor.[ISO/TS-16949], tblVendor.WelcomePackage, tblVendor.SupplierAssessment, tblVendor.InsideSalesContact, tblVendor.InsideSalesPhone, tblVendor.InsideSalesExt, tblVendor.InsideSalesFax, tblVendor.InsideSalesCell, tblVendor.InsideSalesEmail, tblVendor.OutsideSalesContact, tblVendor.OutsideSalesPhone, tblVendor.OutsideSalesExt, tblVendor.OutsideSalesFax, tblVendor.OutsideSalesCell, tblVendor.OutsideSalesEmail, tblVendor.QualityContact, tblVendor.QualityPhone, tblVendor.QualityExt, tblVendor.QualityFax, tblVendor.QualityCell, tblVendor.QualityEmail, tblVendor.MetallurgistContact, tblVendor.MetallurgistPhone, tblVendor.MetallurgistExt, tblVendor.MetallurgistFax, tblVendor.MetallurgistCell, tblVendor.MetallurgistEmail, tblVendor.DistrictMgrContact, tblVendor.DistrictMgrPhone, tblVendor.DistrictMgrExt, tblVendor.DistrictMgrFax, tblVendor.DistrictMgrCell, tblVendor.DistrictMgrEmail
FROM FS_Vendor LEFT JOIN tblVendor ON FS_Vendor.VendorID = tblVendor.VendorID;


Here is the code to the AfterUpdate event of the combobox.

Private Sub cboLookup_AfterUpdate()
    ' Find the record that matches the control.
    Dim rs As Object
    Set rs = Me.RecordsetClone
    rs.FindFirst "[VendorID] = '" & Me.cboLookup.Column(0) & "'"
    If Not rs.EOF Then Me.Bookmark = rs.Bookmark
End Sub


Here is the RowSource for the combobox

SELECT [FS_Vendor].[VendorID], [FS_Vendor].[VendorName] FROM FS_Vendor ORDER BY [FS_Vendor].[VendorName];
I am using a column count of 2 with the bound column being 1


The problem is.... sometimes the form doesn't select the correct record.

Any ideas what is happening?

TIA,
Die-Tech


Answer : Need help with combobox not selecting the correct record

Yes, it does!

The problem is probably in the bookmark, still. When using an ODBC connection, the JetEngine cannot use the indexes on the back end tables, that is why it need you to identify the relevant key field. Basically, this is why I wanted you to identify precisely which field is the actual key, which is the foreign key, etc. At that time, it was not to debug the ODBC link (I have little experience with those anyway), but to have you insert both primary keys in the query...

Another question now is: what is the actual key field in the SQL database? Is there at least a unique index on VendorID (being unique as such is not enough, the engine needs to know that too).

Anyway, it seems you have found the root of the problem. When working accross several systems (Access and SQL Server in this case), you need to make sure they collaborate on the same premisses. You could also consider other, more robust ways to link to SQL Server.

Cheers!
(°v°)
Random Solutions  
 
programming4us programming4us