Results 1 to 4 of 4
  1. #1
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Morecambe England, Lancashire, England
    Posts
    105
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Finding name with a combo box (Windows 98/Office 2000)

    Can anyone help me by explaining the difference between to following two bits of code please?

    In both instances you type a few letters into the combo box. It guesses the name and refines it the more letters you type. Hit enter and the form displays that record.

    I suspect that the second example is a leftover from Access 97, but I would be very grateful if someone could confirm if that is the case and if not the advantages of using one or the other.

    Thanks in anticipation

    Michael Peak
    Morecambe, England


    Private Sub Combo25_AfterUpdate()
    ' Find the record that matches the control.
    Dim rs As Object
    Set rs = Me.Recordset.Clone
    rs.FindFirst "[Album_Name] = '" & Me![Combo25] & "'"
    Me.Bookmark = rs.Bookmark
    End Sub

    Or
    Private Sub Combo25_AfterUpdate()
    ' Find the record that matches the control.
    DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
    Me.RecordsetClone.FindFirst "[Refno] = " & Me![Combo25]
    Me.Bookmark = Me.RecordsetClone.Bookmark
    End Sub

  2. #2
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: Finding name with a combo box (Windows 98/Office 2000)

    Hi,
    There isn't a lot of difference between the two, other than that the second one saves the current record before finding the one typed in the combobox. The default behaviour for a combobox is to match what you type in as you type it - it has nothing to do with the code.
    HTH.
    Regards,
    Rory

    Microsoft MVP - Excel

  3. #3
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Morecambe England, Lancashire, England
    Posts
    105
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Finding name with a combo box (Windows 98/Office 2000)

    Thanks for that Rory,

    I'm pretty sure I undersatand how the combo boxes behave, I was just hoping that some one would clear the fog over the sort of statement:-

    DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70

    and the

    FindFirst
    Me.Bookmark

    Which I don't understand and don't seem to find any article to explain. I can make them work, ok but don't really know what I'm doing!

    Thanks again

    Michael

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Finding name with a combo box (Windows 98/Office 2000)

    DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70

    is Wizard generated code, for some reason the Wizards still produce antiquated Access 95 code. The "modern" equivalent is

    RunCommand acCmdSaveRecord.

    The rest of the code makes a copy (clone) of the record source of the form, and uses FindFirst to locate the first record for which the specified field equals the value entered in Combo25. The Bookmark property of a recordset is a string that uniquely identifies the current record in this recordset. By making the Bookmark property of the form ("Me") equal to the Bookmark of the copy of the recordset, you are effectively moving to the corresponding record.

    You should be able to look up Recordset, Clone and Bookmark in the VBA help.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •