Results 1 to 5 of 5
  1. #1
    fishhead is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Apr 2015
    Posts
    167

    if statement for part of string


    I'm creating an 'if' statement and am not sure how to ask for only part of a thread
    eg: if Forms![fSHANSHPTSCREEN]![Shipper/Consignee] = shanahan*
    open form: abc

    where shanahan might be any of the following:
    shanahan's manu company
    shanahans bldg company

    the key is the field will have the string shanahan in it but will have other characters in the string too. I only want the if statement to search for shanahan and ignore anything after it. Can you suggest the proper argument for the if statement?

  2. #2
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    If "shanahan" will ALWAYS be the first 8 characters, try:
    Code:
        If Left(Forms![fSHANSHPTSCREEN]![Shipper/Consignee], 8) = "shanahan" Then
            DoCmd.OpenForm "ABC"
        End If
    I would recommend NOT using special characters or punctuation in object names. Only letters, numbers and sometimes the underscore.

  3. #3
    fishhead is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Apr 2015
    Posts
    167
    I've entered exactly as you suggested:

    Left([Forms]![fSHANSHPTSCREEN]![Shipper/Consignee],8)='SHANAHAN' then

    but it doesn't see to work.

    Just to be sure I also tried

    Left([Forms]![fSHANSHPTSCREEN]![Shipper/Consignee],8) <> 'SHANAHAN' then
    "
    and it worked fine which is telling me something isn't right with the argument (as the record in question has " SHANAHAN'S - CALGARY (2808-58TH) " stated in the [Shipper/Consignee] field.

    can yo suggest anything else?

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    Is there actually a space in front of SHANAHAN in the data?

    try:

    If Forms![fSHANSHPTSCREEN]![Shipper/Consignee] LIKE "*SHANAHAN*" Then
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    fishhead is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Apr 2015
    Posts
    167
    i should have thought of that! works great thanks!

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

Similar Threads

  1. Replies: 7
    Last Post: 04-14-2015, 03:26 PM
  2. Extract part of string
    By Fais in forum Access
    Replies: 5
    Last Post: 08-06-2014, 04:46 PM
  3. Replies: 6
    Last Post: 09-10-2013, 08:37 AM
  4. Returning part of a string
    By dr4ke in forum Queries
    Replies: 7
    Last Post: 01-15-2013, 11:21 AM
  5. matching part of the string from two columns
    By hoachen in forum Queries
    Replies: 4
    Last Post: 12-20-2011, 01:54 PM

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