Follow-up regarding default table value

X

xRoachx

I'm getting a data type error for the code below:

Dim dtmClassDate as Date

dtmClassDate = FormatDateTime(CurrentDb.TableDefs
("Assignment Sheet").Fields("Class Date").DefaultValue,
vbShortDate)

The field Class Date is a Date/Time field in the
Assignment Sheet table. What I'm trying to do is assign
dtmClassDate a value if the value is not supplied by the
user. I want to use the default value used in the table.
Any ideas as to why I would get a data type error? Thanks.
 
M

Marshall Barton

xRoachx said:
I'm getting a data type error for the code below:

Dim dtmClassDate as Date

dtmClassDate = FormatDateTime(CurrentDb.TableDefs
("Assignment Sheet").Fields("Class Date").DefaultValue,
vbShortDate)

The field Class Date is a Date/Time field in the
Assignment Sheet table. What I'm trying to do is assign
dtmClassDate a value if the value is not supplied by the
user. I want to use the default value used in the table.
Any ideas as to why I would get a data type error? Thanks.


The Format finction always returns a string, not a date/time
value. Since the DafaultValue property is also a string
value, you probably should convert it to a date/time value:

dtmClassDate = CDate(CurrentDb.TableDefs("Assignment
Sheet").Fields("Class Date").DefaultValue)
 

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