Userform TextBox Case and number formating

kakiebos

Board Regular
Joined
Jun 10, 2018
Messages
62
Hi.

I have a User Form to add information in a data list.

In some of the textboxes, I want the information to be added to the list in a certain format.
For example:
1. the engine model to be all in UPPER CASE
2. the manufacturer to be in Proper Case, unless user entered all information in upper case
3. the in service date to be in the format "yyyy-mm-dd" It would also be nice if the user only have to enter 2 digits for the year and not have to enter the seperator.)

I've done some research, but can't seem to find the answer.

my Code so far is:
Code:
Private Sub btAdd_Click()
   Dim r As Long
    'did user input correctly
    If Me.tbESN = VBA.Constants.vbNullString Then
        MsgBox "Please input a Engine Serial Number."
        Me.tbESN.SetFocus
        Exit Sub
    End If
    If Me.tbEModel = VBA.Constants.vbNullString Then
        MsgBox "Please input a Engine Model."
        Me.tbEModel.SetFocus
        Exit Sub
    End If
    
    If IsNumeric(Me.tbESN) = False Then
        MsgBox "Please input a valid number."
        Me.tbESN.SetFocus
        Exit Sub
    End If
'    If IsNumeric(Me.tbCPL) = False Then
'        MsgBox "Please input a valid number."
'        Me.tbCPL.SetFocus
'        Exit Sub
'    End If
    With Engine_Information
        'find the last row
        r = .Range("A" & .Rows.Count).End(xlUp).Row + 1
        
        .Range("A" & r).Value = Val(Me.tbESN)                 ' Number format (8 digits only)
        .Range("B" & r).Value = UCase(tbEModel.Value)         ' UPPER CASE
        .Range("C" & r).Value = Proper(tbMnftr.Value)         ' Proper Case
        .Range("D" & r).Value = Proper(tbMnftrModel.Value)    ' Proper Case
        .Range("E" & r).Value = Val(Me.tbCPL)                 ' Number (4 digits only
        .Range("F" & r).Value = tbInServiceDate               ' Date format (yyyy-mm-dd)
        .Range("G" & r).Value = UCase(tbFno.Value)
        .Range("H" & r).Value = UCase(Me.tbRegNo.Value)
        .Range("I" & r).Value = UCase(Me.TbChassis.Value)
        .Range("J" & r).Value = UCase(Me.tbEngCtrl.Value)
        .Range("K" & r).Value = Proper(Me.tbSiteAddr1.Value)
        .Range("L" & r).Value = Proper(Me.tbSiteAddr2.Value)
        
'        Me.tbCustomer = ""
'        Me.tbValue = ""
    End With


  Unload Me
End Sub
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
I used the following code to force the case that I want in the text box.
Code:
Private Sub tbMnftr_Change()
  tbMnftr.Text = StrConv(tbMnftr.Text, vbProperCase)
End Sub


Private Sub tbMnftrModel_Change()
  tbMnftrModel.Text = StrConv(tbMnftrModel, vbUpperCase)
End Sub

I now only struggle with the date formatting.
 
Upvote 0

Forum statistics

Threads
1,214,377
Messages
6,119,183
Members
448,872
Latest member
lcaw

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top