Problem with Date mismatch

G

Guest

Hi, i have a large form that im trying to manipulate to auto fill some fields
when other fields get typed in. For instance right now the first tab of the
form is the Date tab. If someone inserts the date I would like the Year to be
automatically added on an AfterUpdate Event... here is my code.

Private Sub itemDate_of_Incident_AfterUpdate()
Dim MyDate As Date

MyDate = Forms![frmIncident]![itemDate of Incident].Value
MyVar = CDate(MyDate)

Forms![frmIncident]![itemYear].Value = Year(MyVar)

End Sub

I've tried about everything. It's weird because I can go into the Debug
window and type each of these in seperately and it gives the correct Year in
the year text box.

Any help will be greatly appreciated. Thanks. And im getting an error
message on the line

Forms![frmIncident]![itemYear].Value = Year(MyVar)

I when I put the cursor over Year(MyVar)... it says Type Mismatch
Can't figure it out, lmk. Thanks
 
D

Douglas J. Steele

Assuming itemYear is a text box, is it bound to a field in the form's
recordset? If so, what's the data type of the field to which it's bound? If
it's text, try

Forms![frmIncident]![itemYear].Value = Format(MyDate, "yyyy")

There's no need for MyVar in there.
 
G

Guest

You my friend! Is a genious... Thank you so much, I couldn't figure that out
for the life of me.

Thanks again

Douglas J. Steele said:
Assuming itemYear is a text box, is it bound to a field in the form's
recordset? If so, what's the data type of the field to which it's bound? If
it's text, try

Forms![frmIncident]![itemYear].Value = Format(MyDate, "yyyy")

There's no need for MyVar in there.


--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


AKphidelt said:
Hi, i have a large form that im trying to manipulate to auto fill some
fields
when other fields get typed in. For instance right now the first tab of
the
form is the Date tab. If someone inserts the date I would like the Year to
be
automatically added on an AfterUpdate Event... here is my code.

Private Sub itemDate_of_Incident_AfterUpdate()
Dim MyDate As Date

MyDate = Forms![frmIncident]![itemDate of Incident].Value
MyVar = CDate(MyDate)

Forms![frmIncident]![itemYear].Value = Year(MyVar)

End Sub

I've tried about everything. It's weird because I can go into the Debug
window and type each of these in seperately and it gives the correct Year
in
the year text box.

Any help will be greatly appreciated. Thanks. And im getting an error
message on the line

Forms![frmIncident]![itemYear].Value = Year(MyVar)

I when I put the cursor over Year(MyVar)... it says Type Mismatch
Can't figure it out, lmk. Thanks
 
G

Guest

Actually you ARE a genious... not you is a genious... lol
Either way, thanks!

Douglas J. Steele said:
Assuming itemYear is a text box, is it bound to a field in the form's
recordset? If so, what's the data type of the field to which it's bound? If
it's text, try

Forms![frmIncident]![itemYear].Value = Format(MyDate, "yyyy")

There's no need for MyVar in there.


--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


AKphidelt said:
Hi, i have a large form that im trying to manipulate to auto fill some
fields
when other fields get typed in. For instance right now the first tab of
the
form is the Date tab. If someone inserts the date I would like the Year to
be
automatically added on an AfterUpdate Event... here is my code.

Private Sub itemDate_of_Incident_AfterUpdate()
Dim MyDate As Date

MyDate = Forms![frmIncident]![itemDate of Incident].Value
MyVar = CDate(MyDate)

Forms![frmIncident]![itemYear].Value = Year(MyVar)

End Sub

I've tried about everything. It's weird because I can go into the Debug
window and type each of these in seperately and it gives the correct Year
in
the year text box.

Any help will be greatly appreciated. Thanks. And im getting an error
message on the line

Forms![frmIncident]![itemYear].Value = Year(MyVar)

I when I put the cursor over Year(MyVar)... it says Type Mismatch
Can't figure it out, lmk. Thanks
 

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