Problem with Code after Database Split, Change Seek to FindFirst

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Redbeard
    New Member
    • Oct 2007
    • 112

    Problem with Code after Database Split, Change Seek to FindFirst

    I had to split a database and there is now a problem with the code. I have found by researching online that you cannot use “Seek” in a split database and that is my problem. The suggested fix is using “FindFirst” instead. However, I am not very good with writing code so I am having issues in getting it right. The code is attached to the “After Update” property of a combo box that reads off a table that is now linked. When you click in the combo box it gives you a drop down list of Cities/Provinces/County. When you select the one you want it populates that box and the two below it with the City, Province, and County. I have posted the original code below and then what I have tried to do. Any suggestion?
    Old Code:
    Code:
    Private Sub Source_City_AfterUpdate()
        'If user chooses a city from the list, automatically fill in the corresponding
        'province and country fields
        Dim db As Database
        Dim CityList As Recordset
           
            Set db = CurrentDb()
            Set CityList = db.OpenRecordset("CityProvCountryLookup")
            CityList.Index = "City"
            CityList.Seek "=", Screen.ActiveControl
            DoCmd.GoToControl "[Source Postal Code]"
            
        CityList.Close
        Set CityList = Nothing
        db.Close
        Set db = Nothing
        
    End Sub
    My Attempt: Which does not work.
    Code:
    Private Sub Source_City_AfterUpdate()
        'If user chooses a city from the list, automatically fill in the corresponding
        'province and country fields
        Dim db As Database
        Dim CityList As Recordset
           
            Set db = CurrentDb()
            Set CityList = db.OpenRecordset("CityProvCountryLookup")
            CityList.FindFirst City & "=" & Screen.ActiveControl
    
            DoCmd.GoToControl "[Source Postal Code]"
            
        CityList.Close
        Set CityList = Nothing
        db.Close
        Set db = Nothing
        
    End Sub
  • Redbeard
    New Member
    • Oct 2007
    • 112

    #2
    I fixed it! It was just a simple error of referring to the wrong combo box. Line 9 should be:

    Code:
     CityList.FindFirst [Source City] & "=" & Screen.ActiveControl
    Guess I was closer then I thought?

    Comment

    • TheSmileyCoder
      Recognized Expert Moderator Top Contributor
      • Dec 2009
      • 2322

      #3
      Quick Remark:
      You have the line
      Code:
      db.Close
      Note that you should only close objects you open. You are correct to set db=Nothing (removing the reference to the db), but you should not close what you have not opened.

      Comment

      Working...