Results 1 to 3 of 3
  1. #1
    Khalil Handal is offline Competent Performer
    Windows 10 Access 2010 32bit
    Join Date
    Jun 2016
    Posts
    310

    Divide a string into two parts.

    Hi to all,
    A user types a name in a subform (family name, First Name).
    If the name does not exists (is not in the list), a second form frmNames is opened (with OpenArgs) and the values should be seperated in two text fields: txtFamilyName and txtFirstName.

    In formfrmNames, I have:
    Code:
    strName = Me.OpenArgs
    intCommaPos = InStr(strName, ",")
    If intCommaPos > o Then ' Value passed in includes a comma

    I need to:


    1- text before comma to be in Me.txtFamilyName and text after comma in Me.txtFirstName
    2- Trim both text boxes to avoid any spaces at the beginning.
    3- Use the Ucase function to have only the first letter in capital letter.

    How can this be done?

    Note:
    I have the following code. It has a problem with some special characters like (heinrich böll). It shows like (heinrich b?ll).
    Code:
     If intCommaPos > 0 Then  ' Value passed in includes a comma
                Me.txtFamilyName = StrConv(Trim(Left$(strName, intCommaPos - 1)), vbProperCase, 11265)  
                Me.FirstName = StrConv(Trim(Mid$(strName, intCommaPos + 1, Len(strName))), vbProperCase, 11265)
    Any ideas?

    Khalil

  2. #2
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,933
    depends on how many parts to the name - if there are just two then pretty straightforward - your way (which can also be done in a query)

    lastname: trim(left(strName, instr(strname,",")-1))
    firstname:trim(mid(strName, instr(strname,",")+1))

    or in vba use the split function

    lastname=split(strName,",")(1)
    firstname=split(strName,",")(0)

  3. #3
    Khalil Handal is offline Competent Performer
    Windows 10 Access 2010 32bit
    Join Date
    Jun 2016
    Posts
    310
    Hi,
    I tried few examples and it is doing exactly waht I want.
    Thank you

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

Similar Threads

  1. Concatenate parts of looped string
    By kiwichick in forum Programming
    Replies: 7
    Last Post: 03-10-2020, 10:36 AM
  2. Parts List on Parts Requisition Report
    By billgyrotech1 in forum Access
    Replies: 16
    Last Post: 06-03-2019, 01:17 PM
  3. query to split concatenated string into separate parts
    By ankur_bhardwaj in forum Access
    Replies: 9
    Last Post: 07-12-2016, 12:21 PM
  4. Replies: 3
    Last Post: 08-02-2012, 11:37 AM
  5. divide by zero
    By rbee in forum Access
    Replies: 11
    Last Post: 07-19-2012, 12:55 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