Casting to Date type

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi all

I’ve written a function which has Date arguments. The function is not
working as it should. My best guess here is that this is because the function
is fed its arguments from unbound text boxes. I assume that VB is not
interpreting the text boxes as Dates, even though they are being fed into
Date type arguments. With all due respect, it seems that VB is a bit dense
when it comes to implicit casting.

How do I explicitly cast the text box values to the Date type? I have tried
Date([Text Box]), however VB seems to find this expression a little
confusing. The Help index does not know the word ‘cast’.

Any help, as ever, most gratefully received.

Oh, out of interest, what is the data type of text typed into a text box? I
assume ‘String’?

Thanks again

David
 
There is a CDate function CDate(TextBox)
or in your code you can put # around to show that it is a date
#18/04/2005#
 
For a bound control, Access determines the data type by looking at the field
it is bound to.

Unbound control do default to text. Setting the Format property of the text
box to Short Date or similar will help Access understand what you intend,
and prevent the entry of invalid dates.

For calculated fields, wrap the calculation in CVDate(), or CDate() if no
values could be null.

For parameters in a query, declare them and you get to specify the data
type: Parameters on Query menu.

More info on helping Access understand your dates regardless of the user's
regional settings, see:
International Date Formats in Access
at:
http://allenbrowne.com/ser-36.html
 
Back
Top