• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 341
  • Last Modified:

Updating text in Masked edit box

I have a masked edit box where the mask is ##/## im trying to update the text of this box with the date from a string variable. I cannot get it to work, do not understand why. Please post code of how to get this to work.

txtCCExpDate.Text = OnlyNumericChars(str, Me) 'this string will have a mmdd format

  • 4
  • 3
1 Solution
1)  Post the code for OnlyNumericChars

2)  What are the values of str and Me?

Have you tried:

txtCCExpDate.Text = Format(str,"##/##")

Maybe that would work. I don't have time to test it but it is worth a shot.

DalexanAuthor Commented:
That doesnt work J K M A N, that is the mask though thats on the textbox. Below is the code for OnlyNumericChars, I put a msgbox after the text assignment to find out whats in OnlyNumericChars(str, Me) and I find 0609 which is what I was expecting a string with 4 digits which is a credit card expiration date.

Public Function OnlyNumericChars(ByVal OrigString As String, frmError As Form) As String
'This function will take any non Numeric characters and CHOP them off
On Error GoTo EventHandler
Dim lLen As Long
Dim sAns As String
Dim lCtr As Long
Dim sChar As String
    OrigString = Trim(OrigString)
    lLen = Len(OrigString)
    For lCtr = 1 To lLen
        sChar = Mid(OrigString, lCtr, 1)
        If IsNumeric(Mid(OrigString, lCtr, 1)) Then
            sAns = sAns & sChar
        End If

    OnlyNumericChars = sAns

Exit Function

    GStr_f_end_method = "ConvertVanity()"
    GLng_f_end_number = Err.Number
    GStr_f_end_desc = Err.Description
    GBool_ErrorFlag = True
    Call ErrHandler(frmError)
End Function
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Try this:

txtCCExpDate.Text = Format(OnlyNumericChars(str, Me),"00/00")

The problem was it wasn't putting in the '0' in front of the 6 and the 9 in the case of '0609'

It worked here at least.

Just make sure your string that is returned is ONLY 4 chars long. Mine errors out if it is 5 or more digits unless all the first digits are 0's. Example:

txtCCExpDate.Text = Format("0609","00/00")   - This works

txtCCExpDate.Text = Format("0006089","00/00")   - This works by taking off the leading zeros but it fills it in with 60/89

txtCCExpDate.Text = Format("0106089","00/00")   - This doesn't work. It gives an error.

Good luck

DalexanAuthor Commented:
thanks, testing now
DalexanAuthor Commented:
That works great thanks. What a mess....
Glad it worked out.

Thanks for the grade!

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now