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

    Oneline of code instead of two

    Hi to all,

    Can have these two lines of VBA code in a one line?


    Code:
     Me.txtFamilyName = Trim(Me.txtFamilyName)
        Me.txtFamilyName = UCase(Left(Me.txtFamilyName, 1)) & Mid(Me.txtFamilyName, 2)

    Thanks
    Khalil

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,556
    I believe you could use a : to seperate them, but that to me would make it harder to read?
    Write your code so that it is easy for ANYONE to understand it.
    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

  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Can use Trim() on each instance of txtFamilyName in the second expression.

    Why is Trim needed? Are there leading spaces in data? I suppose users could mistype and cause that.
    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.

  4. #4
    Khalil Handal is offline Competent Performer
    Windows 10 Access 2010 32bit
    Join Date
    Jun 2016
    Posts
    310
    Right. The trim is to remove any leading spaces.

  5. #5
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,932
    you could use

    Me.txtFamilyName = UCase(Left(trim(Me.txtFamilyName), 1)) & Mid(trim(Me.txtFamilyName), 2)

    but it is a bit less readable

  6. #6
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,556
    Perhaps
    Code:
    Me.txtFamilyName = strConv(Me.txtFamilyName,vbProperCase)
    That is one line?

    A lot easier to read as well?
    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

  7. #7
    Khalil Handal is offline Competent Performer
    Windows 10 Access 2010 32bit
    Join Date
    Jun 2016
    Posts
    310
    Hi,
    Thank you all.
    Solved

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    So with Trim:
    Code:
    Me.txtFamilyName = strConv(Trim(Me.txtFamilyName), vbProperCase)
    or
    Me.txtFamilyName = Trim(strConv(Me.txtFamilyName, vbProperCase))
    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.

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

Similar Threads

  1. Replies: 5
    Last Post: 08-29-2016, 04:33 AM
  2. Replies: 20
    Last Post: 10-13-2015, 09:05 AM
  3. Replies: 3
    Last Post: 10-16-2014, 08:49 AM
  4. Replies: 7
    Last Post: 05-28-2013, 09:11 AM
  5. Replies: 1
    Last Post: 05-04-2013, 12:19 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