Results 1 to 4 of 4
  1. #1
    eww is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Aug 2010
    Posts
    125

    Pound sign in text field

    I'm having a strange problem with a search field I have in a form. The code for it reads:



    Private Sub cboProjectSearch_AfterUpdate()
    Me.txtProjectName.SetFocus
    DoCmd.FindRecord Me.cboProjectSearch, acEntire
    End Sub
    Private Sub cboProjectSearch_Click()
    Me.cboProjectSearch = vbNullString
    End Sub

    It works fine except for Projects which have a pound sign in their name (example: "Dorm #1"). I have removed the pound sign in the name and tried the search and it worked. It is just a text field and from what I've read having a pound sign (or pretty much anything else for that matter) in a text field should not be a problem. Is there something wrong with the code that would make it not return a record from the search?

  2. #2
    weekend00 is offline I may not be right
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    1,295
    Following is copied from Acces help file

    Wildcard Characters Used in String Comparisons

    Built-in pattern matching provides a versatile tool for making string comparisons. The following table shows the wildcard characters you can use with the Like operator and the number of digits or strings they match.
    Character(s) in pattern Matches in expression
    ? Any single character
    * Zero or more characters
    # Any single digit (09)
    [charlist] Any single character in charlist
    [!charlist] Any single character not in charlist

    A group of one or more characters (charlist) enclosed in brackets ([ ]) can be used to match any single character in expression and can include almost any characters in the ANSI character set, including digits. In fact, the special characters opening bracket ([ ), question mark (?), number sign (#), and asterisk (*) can be used to match themselves directly only if enclosed in brackets. The closing bracket ( ]) can't be used within a group to match itself, but it can be used outside a group as an individual character.
    In addition to a simple list of characters enclosed in brackets, charlist can specify a range of characters by using a hyphen (-) to separate the upper and lower bounds of the range. For example, using [A-Z] in pattern results in a match if the corresponding character position in expression contains any of the uppercase letters in the range A through Z. Multiple ranges can be included within the brackets without any delimiting. For example, [a-zA-Z0-9] matches any alphanumeric character.
    Other important rules for pattern matching include the following:
    An exclamation mark (!) at the beginning of charlist means that a match is made if any character except those in charlist are found in expression. When used outside brackets, the exclamation mark matches itself.

    The hyphen (-) can be used either at the beginning (after an exclamation mark if one is used) or at the end of charlist to match itself. In any other location, the hyphen is used to identify a range of ANSI characters.

    When a range of characters is specified, they must appear in ascending sort order (A-Z or 0-100). [A-Z] is a valid pattern, but [Z-A] isn't.

    The character sequence [ ] is ignored; it's considered to be a zero-length string ("").

  3. #3
    eww is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Aug 2010
    Posts
    125
    Ah okay, I see how that works now. Do you have any recommendations on how I could maybe right something in to search that. I'm trying to get around either telling the end user that they when they search for something like that they have to put [] brackets around the #, or that they can't put a # at all.

    I'm thinking something along the terms
    If Me.txtProjectName contains a # (I don't how to write this part) Then
    rewrite Me.txtProjectName with [] included around #.
    End If

    Seems like a stretch, I'm just wondering if it's possible.

  4. #4
    eww is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Aug 2010
    Posts
    125
    Solved final code in this thread:

    https://www.accessforums.net/program...ield-8386.html

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 05-05-2010, 02:52 PM
  2. Pound signs restoring tables
    By Djacsnp in forum Access
    Replies: 2
    Last Post: 04-20-2010, 05:42 AM
  3. Daily Sign In form
    By JHansford in forum Access
    Replies: 2
    Last Post: 12-09-2009, 08:41 AM
  4. The ampersand sign (&) and Access reports
    By tigers in forum Reports
    Replies: 2
    Last Post: 09-28-2009, 08:23 AM
  5. Split text field into two text fields
    By Grant in forum Access
    Replies: 6
    Last Post: 01-31-2008, 05:52 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums