Year function - Type mismatch

  • Thread starter Thread starter Cabby
  • Start date Start date
C

Cabby

This procedure in the CustomerCars form works but in the CarDetails form
it doesn't. The inner If statement is strictly for debugging purposes.
Program halts at intTest1 = Year(dteTest1). When I do a cursor
passover of this line, I see the following: intTest1=0, and
Year(dteTest1)=<Type mismatch>.
I have recently re-installed Access 2000. There are 4 references
selected.
Can anyone help?
TIA
Cabby

Private Sub txtPlateYear_AfterUpdate()
If Not Me!cboPlateMonth = "" Then
Me!Plate_expire = ExpiryDate(Me!cboPlateMonth, Me!txtPlateYear)
If IsDate(Me!Plate_expire) Then
dteTest1 = Me!Plate_expire
intTest1 = Year(dteTest1)
End If
Me!txtPlateYear = Year(Me!Plate_expire)
End If
End Sub
 
The problem could be:
- a misunderstanding of the data type of Plate_expire,
- a clash with a name, such as Year, or
- a reference issue.

Is Plate_expire a Date/Time field?

Is dteTest1 declared as a date somewhere, i.e.:
Dim dteTest1 As Date

Is there anything else that has the name Year?
If so, specify the Year() function from the VBA library:
intText1 = VBA.Year(dteTest1)

Are any of your libraries marked as "MISSING"?
From the code window, choose References on the Tools menu.

More info on missing references:
http://allenbrowne.com/ser-38.html

More info on misunderstood data types:
http://allenbrowne.com/ser-45.html
 
Allen, you're right on target.
In table CarDetails is a field called Year and therefore on my CarDetails
form.
I tried using VBA.Year(Me!Plate_expire) and it worked like a charm.
I will now go back and re-name my Year field.
Thanks again.
Cabby
 
Back
Top