Results 1 to 5 of 5
  1. #1
    TonyB is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jul 2011
    Location
    Oxfordshire, UK
    Posts
    16

    Omitting characters from a string

    Hi,



    I have a table storing names in a field called "PrimPerson" in the format [Title] [Firstname] [Surname] (so all the results are return like "Mr Joe Bloggs"). However, some of the names don't have a title and so names just appear as "Joe Bloggs". What I want to do is run some VBA code that says "if the name starts with Mr or Ms or Mrs or Miss then run report X, else run report Y".

    No functions I've tried seem to work. Any help is greatly appreciated!

    Thanks

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,728
    Is this for some sort of academic exercise or demonstration? InN database general, you store atomic fields -fields that can not be decomposed into simpler fields. In your case [Title] [Firstname] [Surname] would be separate fields. You combine fields in queries for display purposes.

  3. #3
    TonyB is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jul 2011
    Location
    Oxfordshire, UK
    Posts
    16
    Yes, but the data has been entered into a table from elsewhere, so I can't split it out. After trying all morning I've finally figured it out:

    Code:
    If InStr(1, [PrimPerson], "Mr") Or InStr(1, [PrimPerson], "Ms") Or InStr(1, [PrimPerson], "Miss") Or InStr(1, [PrimPerson], "Mrs") Or InStr(1, [PrimPerson], "Dr") Then
        DoCmd.OpenQuery "Query1"
    Else
        DoCmd.OpenQuery "Query2"
    End If

  4. #4
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows XP Access 2003
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,544
    What if the first name Is "Missy"
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  5. #5
    TonyB is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jul 2011
    Location
    Oxfordshire, UK
    Posts
    16
    Yeah, I spotted that being a potential problem. I've worked around it now by adding a space to each string. Not perfect I know, but it's ok for what I'm doing

    Code:
    If InStr(1, [PrimPerson], "Mr ") Or InStr(1, [PrimPerson], "Ms ") Or InStr(1, [PrimPerson], "Miss ") Or InStr(1, [PrimPerson], "Mrs ") Or InStr(1, [PrimPerson], "Dr ") Then
        DoCmd.OpenQuery "Query1"
    Else
        DoCmd.OpenQuery "Query2"
    End If

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

Similar Threads

  1. Characters before searched string
    By cleme1q in forum Access
    Replies: 4
    Last Post: 12-10-2011, 11:22 AM
  2. Replies: 4
    Last Post: 12-02-2011, 11:20 AM
  3. Replies: 5
    Last Post: 03-10-2011, 02:19 PM
  4. how select middle characters on string ???
    By ayman.maher in forum Queries
    Replies: 1
    Last Post: 04-27-2010, 09:29 AM
  5. replace characters in a string
    By blazixinfo@yahoo.com in forum Access
    Replies: 6
    Last Post: 08-06-2009, 03:36 PM

Tags for this Thread

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