Solved

Problem reading data from a text box

Posted on 2000-03-14
3
138 Views
Last Modified: 2010-05-02
i am trying to read two numbers out of a textbox(date of birth) and compare those numbers with two other numbers(today's actual date) but for some reason it is only picking up the first digit.  It is not recognizing the second digit.  I have cut and pasted a copy of code.  Can you please help me correct my problem?

Option Explicit
Private Sub cmdCalculateAge_Click()
If txtDOB_month.Text = Month(Date) Then
If txtDOB_day.Text <= Day(Date) Then
    txtCalculatedAge.Text = Year(Date) - txtDOB_year
Else
    txtCalculatedAge.Text = (Year(Date) - txtDOB_year) - 1
End If
Else
If txtDOB_month.Text < Month(Date) Then
    txtCalculatedAge.Text = Year(Date) - txtDOB_year
Else
    txtCalculatedAge.Text = (Year(Date) - txtDOB_year) - 1
End If
End If
End Sub
0
Comment
Question by:sf129
  • 2
3 Comments
 
LVL 27

Expert Comment

by:Ark
ID: 2618362
Hi
Use Val function for textbox.text. For example Val(txtDOB_year).
Cheers
0
 

Author Comment

by:sf129
ID: 2618381
Ark, Good job and enjoy my 60 points.
0
 
LVL 27

Accepted Solution

by:
Ark earned 60 total points
ID: 2618383
Hi
This code works
Option Explicit
Private Sub Command1_Click()
If Val(Text2) = Month(Date) Then
If Val(Text3) <= Day(Date) Then
    Text4 = Year(Date) - Val(Text1)
Else
    Text4 = (Year(Date) - Val(Text1)) - 1
End If
Else
If Val(Text2) < Month(Date) Then
    Text4 = Year(Date) - Val(Text1)
Else
    Text4 = (Year(Date) - Val(Text1)) - 1
End If
End If
End Sub
Cheers
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

914 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