473,396 Members | 2,030 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

text box error

Hi All, having a small error with my date text box. I'm new to this so I might be doing it wrong. :) this is my code

Private Sub Txtbirthdate_click()
frmdefendantsdata.Txtbirthdate.Text = Format(Txtbirthdate.Text, "##/##/####")
End Sub

It works fine I enter 681996 and it comes up 6/8/1996 .....But if I click on the text box again it changs to /68/1996 why. I'm sure there is somthing missing

Thanks for any help Chuck
Sep 27 '07 #1
9 1365
Ali Rizwan
925 512MB
Hi All, having a small error with my date text box. I'm new to this so I might be doing it wrong. :) this is my code

Private Sub Txtbirthdate_click()
frmdefendantsdata.Txtbirthdate.Text = Format(Txtbirthdate.Text, "##/##/####")
End Sub

It works fine I enter 681996 and it comes up 6/8/1996 .....But if I click on the text box again it changs to /68/1996 why. I'm sure there is somthing missing

Thanks for any help Chuck
Ok
I know your problem
you are setting format like this 00/00/0000
means two digits/two digits/four digits
if you enter this text in textbox
09081997
then click anytime the text remains 9/08/1997
try my sugestion.
GOOD LUCK
Sep 27 '07 #2
Ok
I know your problem
you are setting format like this 00/00/0000
means two digits/two digits/four digits
if you enter this text in textbox
09081997
then click anytime the text remains 9/08/1997
try my sugestion.
GOOD LUCK
Thanks for the help and the fast reply
Sep 27 '07 #3
Thanks for the help and the fast reply
Again thanks for the help, changed format to 00/00/0000 and that works well but after date is in place if I click again the date changes to / the day and month / then the year 68/1986 ? thanks for looking again C
Sep 27 '07 #4
Killer42
8,435 Expert 8TB
Can you give us some idea of what you're trying to achieve? You can't really expect to keep applying the same format transformation over and over to something which has already been formatted.
Sep 27 '07 #5
Can you give us some idea of what you're trying to achieve. You can't really expect to keep applying the same format transformation over and over to something which has already been formatted.
Sure, I have 1 text box for the birthdate and 2nd one for age. everthing works fine put birthdate in say 03101964 enter birthdate fill 3/10/1964 age text fills 43 for age. now if you click on the birthday text it changes from 3/10/1964 to 00/02/3446 and errors on the age code. thanks for looking at this again for me

here is the code for both text boxes

Expand|Select|Wrap|Line Numbers
  1. Private Sub Txtbirthdate_click()
  2.   frmdefendantsdata.Txtbirthdate.Text = Format(Txtbirthdate.Text, "00/00/0000")
  3. End Sub
  4.  
  5. Private Sub txtage_gotfocus()
  6.  
  7.   Select Case Month(Txtbirthdate)
  8.     Case Is < Month(Date)
  9.       Txtage = DateDiff("YYYY", Txtbirthdate, Now())
  10.     Case Is = Month(Date)
  11.       Select Case Day(Txtbirthdate)
  12.         Case Is < Day(Date)
  13.           Txtage = DateDiff("YYYY", Txtbirthdate, Now())
  14.         Case Is = Day(Date)
  15.           Txtage = DateDiff("YYYY", Txtbirthdate, Now())
  16.         Case Is > Day(Date)
  17.           Txtage = DateDiff("YYYY", Txtbirthdate, Now()) - 1
  18.       End Select
  19.     Case Is > Month(Date)
  20.       Txtage = DateDiff("YYYY", Txtbirthdate, Now()) - 1
  21.     Case Else
  22.       Txtage = 0
  23.   End Select
  24. End Sub
Sep 28 '07 #6
Killer42
8,435 Expert 8TB
Hm...

Personally I don't think it's a good idea to play around with the format in the one place like this. Anyway, there are probably tons of different things you can do to try and resolve the situation. for example...

Expand|Select|Wrap|Line Numbers
  1. Private Sub Txtbirthdate_LostFocus()
  2.   Dim TempDate As Date
  3.   With Txtbirthdate
  4.     ' If user entered date with slashes (or we have already reformatted)
  5.     ' then convert to an actual date value and back.
  6.     If Instr(.Text, "/") Then
  7.       TempDate = DateValue(.Text)
  8.     Else
  9.       TempDate = DateValue(Format(.Text, "00/00/0000")
  10.     End If
  11.     .Text = Format(TempDate, "Short date")
  12.   End With
  13. End Sub
Oh, and drop the Click event procedure.



However, perhaps the simplest (and most bullet-proof) solution would be to use a DateTimePicker control instead of a textbox. This provides a dropdown calendar in which the user can choose a date. Or possibly a MaskedEdit control, which is like a textbox but imposes a specified format on what the user enters. That way, you could force the date to be input as a date.
Sep 28 '07 #7
Ali Rizwan
925 512MB
Again thanks for the help, changed format to 00/00/0000 and that works well but after date is in place if I click again the date changes to / the day and month / then the year 68/1986 ? thanks for looking again C
See Msedic
Your code is right there is no problem in your code but remember a day must have two digits, month must have two digits ans year must have four digits like
Day 01,02,03,04,05,06,07,08,09,10,11,12,....,31
Right
Month 01,02,03,04,05,06,07,08,09,10,11,12
Right
And
Year 1997 or 2001
Right now try to put this text in textbox
01021997
and click any number of time the textremain 1/02/1997
Remember there is no error in your code error is in your text writing in text field.
Sep 28 '07 #8
Ali Rizwan
925 512MB
Hi All, having a small error with my date text box. I'm new to this so I might be doing it wrong. :) this is my code

Private Sub Txtbirthdate_click()
frmdefendantsdata.Txtbirthdate.Text = Format(Txtbirthdate.Text, "##/##/####")
End Sub

It works fine I enter 681996 and it comes up 6/8/1996 .....But if I click on the text box again it changs to /68/1996 why. I'm sure there is somthing missing

Thanks for any help Chuck
Oh
Im sorry i have posted on wrong ones
Sep 28 '07 #9
Oh
Im sorry i have posted on wrong ones
Thanks for all your help C
Sep 28 '07 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Stephen Saunders | last post by:
Hey Folks, This one currently has me stumped. I have to check for the existence of a carriage return (Enter key, hex 0D) in text data. First I tried: 'Check comment to not contain the CR...
4
by: kalio80 | last post by:
Hi everyone I posted an enquiry earlier about using c++ code to convert text files between linux & widows. I ended up with this code: #include <iostream> #include <fstream> using namespace...
0
by: Lauren Wilson | last post by:
The error does not have an error number. It's not even a normal Access error message box. Hope someone has some insight to this problem. I have a form that contains a large (5" x 4") text box...
9
by: anachronic_individual | last post by:
Hi all, Is there a standard library function to insert an array of characters at a particular point in a text stream without overwriting the existing content, such that the following data in...
24
by: garyusenet | last post by:
I'm working on a data file and can't find any common delimmiters in the file to indicate the end of one row of data and the start of the next. Rows are not on individual lines but run accross...
13
by: =?Utf-8?B?S2VzdGZpZWxk?= | last post by:
Hi Our company has a .Net web service that, when called via asp.net web pages across our network works 100%! The problem is that when we try and call the web service from a remote machine, one...
2
by: flyzone | last post by:
Goodmorning people :) I have just started to learn this language and i have a logical problem. I need to write a program to parse various file of text. Here two sample: --------------- trial...
4
cassbiz
by: cassbiz | last post by:
Could use some help here. This script is carrying over an image just fine but the text isn't coming over. can you see why it is not working???? from the form I want to carry over two lines of...
4
by: jdokos | last post by:
Hello All, I have a procedure that is getting -443 after upgrading to V9.5 FP1. The procedure was written to output only the SQLCODE. Here is the output that is returned: Value of output...
16
by: Wayne | last post by:
I've read that one method of repairing a misbehaving database is to save all database objects as text and then rebuild them from the text files. I've used the following code posted by Lyle...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.