Results 1 to 7 of 7
  1. #1
    Lou_Reed is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2015
    Posts
    1,664

    This code compiles but does not work

    I have tried this code shown now:

    Code:
    Public Function PCase(anyText) As String
       PCase = StrConv(anyText, vbProperCase)
       
       If Left(PCase, 2) = "Mc" Then
            PCase = "Mc" & UCase(Mid(PCase, 3, 1)) & Mid(PCase, 3)
       End If
                    
       Debug.Print "PCase = " & PCase
       
    End Function
    I am trying to get proper capitalization. Say, PCASE(JAMES) = James, then PCASE(MCDONALD) = McDonald.




    What I am getting is

    PCASE =

    and nothing more.

    I am unsure where my error is.

    Any help appreciated.

    Thanks in advance.

    Respectfully,

    Lou Reed

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    I would start by suggesting you use

    Debug.Print "PCase = [" & PCase & "]"
    Then you have a better idea what is happening.

    Have you single stepped the code to see what is in the variables?

  3. #3
    Lou_Reed is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2015
    Posts
    1,664
    I know what is going wrong. I should input it like this

    PCASE("JAMES")

    PCASE = James


    Then

    PCASE("MCDONALD")

    PCASE = McDdonald

    Now if I can just get the small d in McDdonald out.

    Respectfully,

    Lou Reed

  4. #4
    JoeM is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    PCASE = McDdonald

    Now if I can just get the small d in McDdonald out.
    That is because you are repeating that character.

    Change this:
    Code:
    PCase = "Mc" & UCase(Mid(PCase, 3, 1)) & Mid(PCase, 3)
    to this:
    Code:
    PCase = "Mc" & UCase(Mid(PCase, 3, 1)) & Mid(PCase, 4)

  5. #5
    Lou_Reed is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2015
    Posts
    1,664
    I think that that is the answer. You are right. Thanks for your help.

    Respectfully,

    Lou Reed

  6. #6
    JoeM is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Your welcome.

    Essentially, what you were saying with this:
    Code:
    UCase(Mid(PCase, 3, 1))
    is add the 3rd letter of Pcase to your string but capitalize it.

    Then this last part:
    Code:
    & Mid(PCase, 3)
    says to add everything from the 3rd letter of Pcase to the end.
    But since you already accounted for the 3rd letter in the previous part, you actually want to start at the 4th letter, not the 3rd.

  7. #7
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    I marked this thread as *Solved* for you using the *Thread Tools* at the top of the thread.
    https://www.accessforums.net/showthread.php?t=1828

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

Similar Threads

  1. Code Does not work
    By larabeelw in forum Access
    Replies: 11
    Last Post: 11-27-2013, 03:18 PM
  2. vba code dont work
    By mikichi in forum Programming
    Replies: 7
    Last Post: 11-12-2013, 01:59 PM
  3. VBA code used to work now it does not
    By rachello89 in forum Programming
    Replies: 9
    Last Post: 06-15-2012, 08:48 AM
  4. Replies: 1
    Last Post: 03-07-2012, 02:00 PM
  5. VBA Code To Work With MySQL
    By botts121 in forum Programming
    Replies: 0
    Last Post: 07-08-2009, 08:51 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