Results 1 to 4 of 4
  1. #1
    MsAxes is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Oct 2021
    Posts
    100

    How can IF check matches two exact values and contains a specific text on other fields?

    I have an if statement in a module that is looking at four fields to see if the criteria below is met. I am having trouble in checking fields Code1 and Code2 to see if they end with a specific text (field is 6-7 characters); one should end in AM and the other in BM.

    My first approach was to check if they contain AM or BM which is why you see InStr, but that isn't working. As I wrote this post, I think its best to check they end in those characters but don't know how to adjust from here.

    Field Value
    Cat CL <--- exact match
    ValRule M - M <--- exact match
    Code1 AM <----ends in AM


    Code2 BM <----ends in BM

    Code:
    If Cat = "CL" And ValRule = "M - M" And InStr(1, Code1, "AM") > 0 And InStr(1, Code2, "BM") > 0 Then
    
    Test = "Pass"

  2. #2
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2013 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,101
    Try:
    Right([YourField],2)="AM"

    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  3. #3
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,858
    Youmight want to review these functions, as you appear to have needed some of them in your recent posts?

    https://bettersolutions.com/vba/stri.../functions.htm
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  4. #4
    MsAxes is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Oct 2021
    Posts
    100
    Thank you both, I appreciate it.

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

Similar Threads

  1. Replies: 11
    Last Post: 06-07-2018, 05:19 PM
  2. Extract text when it matches specific format
    By newbiecoder in forum Access
    Replies: 21
    Last Post: 05-31-2018, 11:02 PM
  3. Replies: 26
    Last Post: 06-21-2017, 08:49 AM
  4. Replies: 7
    Last Post: 02-29-2016, 06:13 PM
  5. Query for not exact matches in two tables
    By FrankBone in forum Queries
    Replies: 1
    Last Post: 06-03-2015, 12:49 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