Results 1 to 7 of 7
  1. #1
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,195

    Fore Name and Or surname

    Hi Guys, can anyone see the wood here ? i can't see the wood for the trees



    If a text box has got Joe Bloggs in it, i am trying to return Joe

    If a text box has only got Joe in it, i am still trying to return Joe

    If a text box has got Mr Bloggs in it, i am trying to return Mr Bloggs (Not got this far yet to add code that if the text box says Mr or Mrs so needs adding to what i have got here below)

    Dim FullName as string, fName as String, sName as string

    FullName = InStr(Me.txtClientName, " ")
    If FullName <> "" Then
    fName = Left(Me.txtClientName, FullName) 'Does return Joe
    End If
    If FullName = "" Then
    fName = Left(Me.txtClientName, "") 'RETURNS NOTHING
    End If

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,928
    Name parts should be in separate fields. Trying to break them apart is a nightmare.

    FullName is declared as a string but you set it to a number.

    The second Left() function is not correctly used. Its second argument must be a number or an expression that returns a number, not an empty string. Why would you use Left() for that case anyway?

    Need to test for Mr and Mrs but what about Ms, Dr, Senator and other courtesy titles?
    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.

  3. #3
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    And what about names like

    Mary Anne Smith
    George Huntingdon Smith

  4. #4
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,195
    ahh thank you very good point to replies you have sent

    Would you be able to do a method in vba that would accommodate all ?

    Kindest

  5. #5
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    Would you be able to do a method in vba that would accommodate all ?
    all depends on the specifics - often requires a high level of customisation

  6. #6
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    the techniques used might be to use the following string functions, instr, instrrev, left, mid, right. In vba you might also use the split function to split your single field on space into multiple elements which you can loop through and examine and treat as required.

    depends on whether this is a one off exercise to create the additional fields to go forward with or something you need to do on a regular basis.

    One way or another you will almost certainly find fullnames which don't match the patterns you have already identified so best way to proceed is identify and fix the easy ones so you can focus on the more complex ones and improve your routines to cater for them.

    You may find this link helpful

    http://www.cpearson.com/Excel/FirstLast.htm

    It's in excel, but the vba principle should still apply

  7. #7
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,195
    Thank you so much guys, i believe with so many IF cases or Selects cases then strings could be created but i will check out what you have suggested

    Kindest

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

Similar Threads

  1. Replies: 15
    Last Post: 08-02-2018, 07:22 AM
  2. Replies: 7
    Last Post: 08-13-2017, 11:18 PM
  3. Open form with matching surname
    By l3111 in forum Forms
    Replies: 8
    Last Post: 06-02-2011, 07:16 AM
  4. Replies: 7
    Last Post: 03-03-2010, 11:06 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