After update - If Like Else else

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • david bonsall
    New Member
    • Jun 2008
    • 3

    #1

    After update - If Like Else else

    I have a field called [Client_number] and the value of that field can be deciphered into a location for that client.

    Eg. SU[any letter]023[000-999] = UK
    SA[anyletter]024[000-999] = Australia

    ....so SUR023023 = UK, whereas SUT024076 = Australia.

    This is simplified as there are 30 possible locations.

    I would like a field called [location] that returns the correct location. I tried the following in the AfterUpdate box for the [Client_number] field.

    If [Client_number] Like "[SU]?[023]*" Then
    [Location] = "UK"
    ElseIf [Client_number] Like "[SA]?[024]*" Then
    [Location] = "Australia"
    End If

    ...but it doesn't work. It returns "UK" for either "Likes".

    Any suggestions?

    Thanks

    David
  • ADezii
    Recognized Expert Expert
    • Apr 2006
    • 8834

    #2
    By using Brackets ([ ]) with the Like Operator, you were testing for any 'single character' in the Range, try:
    Code:
    If [Client_number] Like "SU?023*" Then
      [Location] = "UK"
    ElseIf [Client_number] Like "SA?024*" Then
      [Location] = "Australia"
    Else
      'whatever
    End If

    Comment

    • david bonsall
      New Member
      • Jun 2008
      • 3

      #3
      Thanks a bunch,

      It works a dream. Just one more thing. This code only works in the Form and I can't get it to work in Table format (there doesn't appear to be an afterupdate option in the table and I don't know how to input the code). I need it to work in table form because I plan to import a large amount of data from excel.

      Any ideas?

      Regards

      David

      Comment

      • missinglinq
        Recognized Expert Specialist
        • Nov 2006
        • 3533

        #4
        As explained in your thread http://bytes.com/forum/thread817865.html fields in tables do not have events. You failed to mention, in your other thread, that your problem involves importing data into a table. Even if you were using a table, the AfterUpdate event wouldn't fire when the data was imported, as it only fires if data is physically entered into a textbox, not when data is entered thru code.

        Perhaps if you explained exactly what it is you're trying to accomplish we could help you with a solution.

        Linq ;0)>

        Comment

        • NeoPa
          Recognized Expert Moderator MVP
          • Oct 2006
          • 32669

          #5
          David, It's far easier to help you if you :
          1. Include all relevant information in your original question.
          2. Do not double post on the same issue.

          Having been involved in setting up the rules for the site, I can confirm that that's exactly why the rules (http://bytes.com/forum/faq.php?faq=t...ing_guidelines) were set up to include the above stipulations.

          Comment

          • NeoPa
            Recognized Expert Moderator MVP
            • Oct 2006
            • 32669

            #6
            As far as your problem is concerned, you may have to run an update query against a table (where the logic is stored) which updates the newly created records from your import.

            Let us know (in here) if you would like help formulating this process.

            Comment

            Working...