Form field stores text rather than date

50gumbys

Board Regular
Joined
Nov 12, 2002
Messages
54
I have a form with a date field that doesn't check if an actual date has been entered - and won't check with my coding. It lets you type anything into it.

I initialise the form by setting the fields to empty, and the code for the DATE field is as follows:

txtDOB.Text = Format (Now - (365.25 * 18), "dd/mm/yy")

I tried to define a keyword other than Text for this field, but there was no Date option

I've included an error handling routine to check that a proper date has been entered, but since I think my first statement dictates the field's content, it doesn't work either.

When the fields are filled, I have coding to transfer data to the spreadsheet and that works fine.

I hope this is enough information.

I greatly appreciate your help!
Kind regards,
Lori Hughes
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
The .Text and .Value properties of TextBoxes are always String, never Date.

To test if a TextBox contains a string that is a representation of a Date, you could use
Code:
[code]MsgBox IsDate(TextBox1.Text)
 
Upvote 0
Thank you for your help here.

Oh dear! (your message just hit me!)

How can I create a field to contain a date then?
 
Upvote 0
You don't. You write code knowing that the field will contain a string and use validation techniques to assure that that string can be treated as a date.
 
Upvote 0
Yikes - So I would need the validate on entering the field to allow a date.

I have no idea how to do that?
Can you help please????
 
Upvote 0

Forum statistics

Threads
1,223,239
Messages
6,170,947
Members
452,368
Latest member
jayp2104

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top