Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    data808 is offline Noob
    Windows 8 Access 2007
    Join Date
    Aug 2012
    Posts
    727

    How to make all caps for a text box

    How do you make a text box automatically capitalize letters that are typed in?

  2. #2
    amrut is offline Expert
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2012
    Location
    India
    Posts
    616
    Use text box change event -
    Code:
    Private Sub Text55_Change()
    On Error Resume Next
    DoCmd.RunCommand acCmdSaveRecord
    Me.Text55.Value = VBA.UCase(Me.Text55.Value)
    Me.Text55.SelStart = Len(Me.Text55)
    End Sub

  3. #3
    data808 is offline Noob
    Windows 8 Access 2007
    Join Date
    Aug 2012
    Posts
    727
    Thanks. But just out of curiosity, why is there a save command in there? Also is the Text55 the actual name of the text box? And what does SelStart and Len do?

    Sorry but kinda new to VBA and want to learn more.

    I also found an easier way to make it caps. Go to the Format property of the text box and enter > symbol in it. The only thing I don't like about it is that it does not show the capital letters until the text box loses focus. Would you know an easy way like this to make the text box show capitals as you type them?

  4. #4
    amrut is offline Expert
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2012
    Location
    India
    Posts
    616
    Text55 is name of text box whose value you wish to change to upper case.
    Code:
    Private Sub Text55_Change()
    On Error Resume Next                                         'if value is null access will throw error
    DoCmd.RunCommand acCmdSaveRecord                 'if not saved, the current text cannot be retrieved in next line
    Me.Text55.Value = VBA.UCase(Me.Text55.Value)     ' Sets the case to upper
    Me.Text55.SelStart = Len(Me.Text55)                    'Sets the cursor to the end of text other wise it will always be at the beginning
    End Sub
    Mark the thread as solved if your problem is solved

  5. #5
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Quote Originally Posted by data808 View Post

    ...Would you know an easy way like this to make the text box show capitals as you type them...
    Sure, the six lines of code amrut gave you! Writing 6 lines of code is not exactly onerous!

    BTW, using > not only doesn't effect the display until you exit the Control, if focus returns to the Control the data returns to the non-capitalized version until you once again exit it. Also, with some versions of Access, under some conditions, formatting with the > (actually, anything done in the Format Property) can cause data to 'disappear.'

    Linq ;0)>

  6. #6
    data808 is offline Noob
    Windows 8 Access 2007
    Join Date
    Aug 2012
    Posts
    727
    The code does not work because I have some VBA already prompting me in the before update event to ask if I am sure that I want to save the changes. Can anyone give me some code that does not have to include a save command?

    Yes I realized that when leaving focus is when the caps show and setting focus back to the text box it will then go back to lowercase. I don't like this and I also don't like the part you mentioned that sometimes the data can disappear. I don't want that to happen.

  7. #7
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Code:
    Private Sub TextBoxName_KeyPress(KeyAscii As Integer)
       KeyAscii = Asc(UCase(Chr(KeyAscii)))
    End Sub

    Just replace TextBoxName with the actual name of your Control.

    Linq ;0)>

  8. #8
    JeroenMioch's Avatar
    JeroenMioch is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2012
    Location
    Den Haag, Netherlands
    Posts
    368
    That works nice mr. Linq
    But if someone copy and pastes his data in the textbox ?

    I have implemented your code and im keeping my afterupdate event as well for above reasons

    Code:
    Private Sub YourTextBox_AfterUpdate()
    Me.YourTextBox = UCase(Me.YourTextBox)

  9. #9
    data808 is offline Noob
    Windows 8 Access 2007
    Join Date
    Aug 2012
    Posts
    727
    This is wonderful. Thank you so much. This works great on the text boxes that I type data into but I do have one text box that is locked because it updates with the user's initials when they edit the record so I don't type anything into this text box. It automatically fills. So this code doesn't work for that. Would you know how to make a text box like this locked one, be all caps too?

    Thanks again for the help. This was really helpful.

  10. #10
    data808 is offline Noob
    Windows 8 Access 2007
    Join Date
    Aug 2012
    Posts
    727
    Ok this is also helpful. I didn't even think about the copy and paste. But this doesn't cover an auto-fill text box. I have a few boxes that automatically fill in data when records are edited. How do you make a text box such as this, all caps?

  11. #11
    data808 is offline Noob
    Windows 8 Access 2007
    Join Date
    Aug 2012
    Posts
    727
    Still need help with the auto fill text boxes. Do you know how to make those all caps? I have it locked so the user will not enter data into it. It will auto fill when the user enters certain information in other text boxes.

  12. #12
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    What is auto fill?

  13. #13
    data808 is offline Noob
    Windows 8 Access 2007
    Join Date
    Aug 2012
    Posts
    727
    I have text boxes that will pull data from another text box when certain text boxes get typed into. For example, when a record is edited, I have the username from the login form transfer over to the current form that the user is entering data so I know who updated the record. Since these text boxes that the username is transferred to is not physically typed into but automatically filled in by the VBA, all the methods listed above to make text boxes capital do not work. Would you have a solution to this? In the beginning of the post it was already suggested that I use > in the format property which I heard was a bad idea because it can cause data to be lost and I also do not like how it only stays capital when it does not have focus. If you put focus on it it will then reveal lowercase till you lose focus again. Please keep that in mind if you have any suggestions. Thanks for whatever help you can provide.

  14. #14
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Quote Originally Posted by data808 View Post
    ...automatically filled in by the VBA....

    You can use the fStrConv() function in VBA to format as upper case.
    Apply your string variable to the first argument abd the constant, vbUpperCase, to the second argument.

    where MyString is the variable your existing code uses to populate the unbound textbox.
    Me.TextboxName.Value = StrConv(MyString, vbUpperCase)

  15. #15
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    As you've said, most Control-related events don't fire when a Control is populated using VBA code. The trick, then, is to Call whichever event you need. So, if you're using this to change the data to upper case:
    Code:
    Private Sub YourTextBox_AfterUpdate()
      Me.YourTextBox = UCase(Me.YourTextBox)
    End Sub

    after the code that populates the Textbox, simply Call the Sub:

    Code:
    'Code to transfer data to Textbox goes here
    Call YourTextBox_AfterUpdate

    Linq ;0)>

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. How to Set Font to Small Caps using VBA
    By EddieN1 in forum Access
    Replies: 3
    Last Post: 04-11-2014, 05:39 AM
  2. Make Text Large in ControlTip?
    By LindaRuble in forum Programming
    Replies: 2
    Last Post: 04-21-2013, 10:30 PM
  3. Convert VALUE in Textbox to CAPS in TABLE
    By taimysho0 in forum Programming
    Replies: 3
    Last Post: 12-30-2011, 05:04 PM
  4. How do you make a text box display a value from a table?
    By italianfinancier in forum Reports
    Replies: 3
    Last Post: 06-01-2011, 12:15 PM
  5. Make text click-able
    By Fifa in forum Access
    Replies: 5
    Last Post: 03-27-2011, 06:44 PM

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