DateSerial function generates Run-time error 13: Type mismatch

R

Rob S.

Access 2002 - I'm generating a date to add a few new records automatically
On one form new code
Dim vTransDate As Date
vTransDate = DateSerial(Year(Now()), Month(Now()), 1)
the DateSerial function generates Run-time error 13: Type mismatch

but on another form old code
Dim vTodaysDate As Date
vTodaysDate = DateSerial(Year(Now()), Month(Now()), Day(Now()))
works fine

knowledge base article said to select the MS DAO 3.6 object library, which I
did, without really knowing what I'm doing. No change. Article also said to
create a new database first, but I need this to work in the old database.
Any fix tried, or maybe there is a better way to get a date declared. Thank
you.
 
D

Douglas J. Steele

By any chance do you have anything on that form named any of DateSerial,
Year, Month or Now? (variables, controls on the form, functions, fields in a
table, anything...)
 
R

Rob S.

Yes: Form record source query has calculated fields
Year: Year([Trans Date])
Month: Month([Trans Date])
These fields appear on form with names IEYear and IEMonth, respectively. Do
I need to do some renaming to eliminate ambiguity?
 
D

Douglas J. Steele

Yes.

Year and Month are both reserved words, and you should never use reserved
words for your own purposes. For a comprehensive list of names to avoid (as
well as a link to a free utility that will check your application for
compliance), see what Allen Browne has at
http://www.allenbrowne.com/AppIssueBadWord.html

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Rob S. said:
Yes: Form record source query has calculated fields
Year: Year([Trans Date])
Month: Month([Trans Date])
These fields appear on form with names IEYear and IEMonth, respectively.
Do
I need to do some renaming to eliminate ambiguity?

Douglas J. Steele said:
By any chance do you have anything on that form named any of DateSerial,
Year, Month or Now? (variables, controls on the form, functions, fields
in a
table, anything...)
 
R

Rob S.

OK. Thank you very much! And you know, I think I have struggled with this
same issue before, without ever getting fully to the real problem, always
developing some cockamammie workaround instead. Thanks again.

Douglas J. Steele said:
Yes.

Year and Month are both reserved words, and you should never use reserved
words for your own purposes. For a comprehensive list of names to avoid (as
well as a link to a free utility that will check your application for
compliance), see what Allen Browne has at
http://www.allenbrowne.com/AppIssueBadWord.html

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Rob S. said:
Yes: Form record source query has calculated fields
Year: Year([Trans Date])
Month: Month([Trans Date])
These fields appear on form with names IEYear and IEMonth, respectively.
Do
I need to do some renaming to eliminate ambiguity?

Douglas J. Steele said:
By any chance do you have anything on that form named any of DateSerial,
Year, Month or Now? (variables, controls on the form, functions, fields
in a
table, anything...)

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Access 2002 - I'm generating a date to add a few new records
automatically
On one form new code
Dim vTransDate As Date
vTransDate = DateSerial(Year(Now()), Month(Now()), 1)
the DateSerial function generates Run-time error 13: Type mismatch

but on another form old code
Dim vTodaysDate As Date
vTodaysDate = DateSerial(Year(Now()), Month(Now()), Day(Now()))
works fine

knowledge base article said to select the MS DAO 3.6 object library,
which
I
did, without really knowing what I'm doing. No change. Article also
said
to
create a new database first, but I need this to work in the old
database.
Any fix tried, or maybe there is a better way to get a date declared.
Thank
you.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top