+ Reply to Thread
Results 1 to 2 of 2

adding option to add letter to first character in text box

Hybrid View

  1. #1
    Registered User
    Join Date
    05-31-2014
    Location
    New Zealand
    Posts
    31

    adding option to add letter to first character in text box

    Hi,

    I have a userform that enters a serial number in a style based on the format of the seerial on the unit.. so it might be 123-456 or 00000-00000 this is working fine and i have added an additional type, Only needs a letter B or S in front ie B-123456-1233445. If i wanted to add a letter to the start, what would i do to change the code. i have tried adding a letter to the code, missing something but not sure what. I just need either any letter or either S or B I have highlighted the lines i think i need to change in red.

    cheers mark

    Private Sub ComboBox1_Change()
        If ComboBox1.Value = ("Transmission Unit LL") Then Me.TBserial = ("00000000000-00000000")
        If ComboBox1.Value = ("Transmission Unit GPRS") Then Me.TBserial = ("00000000000-00000000")
        If ComboBox1.Value = ("Base Unit") Then Me.TBserial = ("00000000000-00000000")
        If ComboBox1.Value = ("Display Units") Then Me.TBserial = ("B-00000000000-00000000")
        If ComboBox1.Value = ("ComBox PSTN") Then Me.TBserial = ("000-000-000000")
        If ComboBox1.Value = ("ComBox GSM") Then Me.TBserial = ("000-000-000000")
        If ComboBox1.Value = ("Dect Meter") Then Me.TBserial = ("000-000-000000")
        
        Me.TBserial.SetFocus
        Me.TBserial.SelStart = 0
    End Sub
    
    Private Sub TBserial_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
        Dim a As Integer
        Select Case KeyCode
            Case 48 To 57
                a = TBserial.SelStart
                Select Case ComboBox1.Value
                    Case "Transmission Unit LL", "Transmission Unit GPRS", "Base Unit"
                        If a = Len("00000000000-00000000") Then KeyCode = 0
                    Case "Display Units"
                        If a = Len("B-00000000000-00000000") Then KeyCode = 0
                    Case "ComBox PSTN", "ComBox GSM", "Dect Meter"
                        If a = Len("000-000-000000") Then KeyCode = 0
                End Select
                
                TBserial.Text = Left(TBserial.Text, a) & Chr(KeyCode) & Mid(TBserial.Text, a + 2)
                a = a + 1
                TBserial.SelStart = a
                If Mid(TBserial.Text, a + 1, 1) = "-" Then
                    TBserial.SelStart = a + 1
                End If
                
                KeyCode = 0
            Case 9, 10, 13
                
            Case Else
                KeyCode = 0
        End Select
    End Sub

  2. #2
    Registered User
    Join Date
    05-31-2014
    Location
    New Zealand
    Posts
    31

    Re: adding option to add letter to first character in text box

    solved my issue. changed the following line from 57 to 90

    Case 48 To 57

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Adding Multiple Selected Option Text to a common Text Box.
    By venkcris in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-05-2014, 11:15 PM
  2. Adding Multiple Cells Text with Special Character
    By sunnyujjawal in forum Excel General
    Replies: 8
    Last Post: 09-03-2013, 09:25 AM
  3. Replies: 8
    Last Post: 04-22-2013, 12:24 PM
  4. Replies: 5
    Last Post: 07-13-2006, 12:15 AM
  5. Inserting a text character via a menu option into...
    By Dave Moran in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-29-2006, 09:30 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1