• ‘ in a name (Access03)

    Author
    Topic
    #436468

    I am using a combo box to locate records using the Access created coding as below.

    Private Sub Combo2_AfterUpdate()
    ‘ Find the record that matches the control.
    Dim rs As Object

    Set rs = Me.Recordset.Clone
    rs.FindFirst “[Division] = ‘ ” & Me![Combo2] & ” ‘ ”
    If Not rs.EOF Then Me.Bookmark = rs.Bookmark
    End Sub

    I am selecting a Division with the combo box and assigning departments to that division. The problem is that one of the Divisions has a ‘ in it’s name: Women’s Pavilion. I can’t get it to work. I think I need to add quotes, but I can’t get it to work. Thank you.

    Fay

    Viewing 0 reply threads
    Author
    Replies
    • #1034881

      If none of the divisions contain a double quote ", you can use

      rs.FindFirst "[Division] = " & Chr(34) & Me![Combo2] & Chr(34)

      Chr(34) represents the double quote character. If you have both single and double quotes in the entries, it becomes a little bit more complicated; let me know if you need that.

      • #1034887

        That is exactly what I needed thank you! Fay

      • #1035779

        Hans,

        I just came across this post while doing a search.

        I have a situation exactly like this except I need to search on fields including single and double quotes.

        How much more complicated does it get to handle both?

        Thanks,
        Sam

        • #1035781

          Using the same expression as in my previous reply:

          rs.FindFirst "[Division] = " & Chr(34) & Replace(Me![Combo2], Chr(34), Chr(34) & Chr(34)) & Chr(34)

          The Replace function replaces all double quotes ” within the value of Combo2 with two double quotes “”.

    Viewing 0 reply threads
    Reply To: ‘ in a name (Access03)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: