Solved

Updating text in Masked edit box

Posted on 2006-06-13
8
307 Views
Last Modified: 2010-04-30
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

0
Comment
Question by:Dalexan
  • 4
  • 3
8 Comments
 
LVL 12

Expert Comment

by:Preece
ID: 16898225
1)  Post the code for OnlyNumericChars

2)  What are the values of str and Me?

Preece
0
 
LVL 3

Expert Comment

by:J_K_M_A_N
ID: 16899324
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.

J_K_M_A_N
0
 

Author Comment

by:Dalexan
ID: 16902185
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
    DoEvents
    Next

    OnlyNumericChars = sAns

Exit Function

EventHandler:
    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
0
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
LVL 3

Accepted Solution

by:
J_K_M_A_N earned 75 total points
ID: 16903295
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.

J_K_M_A_N
0
 
LVL 3

Expert Comment

by:J_K_M_A_N
ID: 16903357
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

J_K_M_A_N
0
 

Author Comment

by:Dalexan
ID: 16903387
thanks, testing now
0
 

Author Comment

by:Dalexan
ID: 16903498
That works great thanks. What a mess....
0
 
LVL 3

Expert Comment

by:J_K_M_A_N
ID: 16903640
Glad it worked out.

Thanks for the grade!

J_K_M_A_N
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from 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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now