Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error in Code: Compile error. Please take a look. 1

Status
Not open for further replies.

BillMc

Programmer
Dec 8, 2000
45
US
My Form name is ORPInsForm. The field I am working with is called YRID. On exiting my field named VehicleID the event procedure occurs:

[tt]Private Sub VehicleID_Exit(Cancel As Integer)
YrID = Year(Date)
End Sub
[/tt]

so the result is 2001

and that works.

However, I want to be able over-write the entry after the event procedure occurs to let's say 2002 and have it not be changed by running the event procedure again. I created this formula:

[tt]Private Sub VehicleID_Exit(Cancel As Integer)
If Forms!ORPInsForm!YrID!>1 Then YrID
else
Year(Date)
End Sub
[/tt]

I am getting a compile error. What is wrong with this code?

Thanks, Bill

Bill@bMcAuley.com

 
It doesn't appear you are setting any values. Try this instead...

Private Sub VehicleID_Exit(Cancel As Integer)

If not Forms!ORPInsForm!YrID!>1 Then
YrID = Year(Date)
End if

End Sub

In your original code, it appears you do not want to change the value if your condition is true. Therefore, if the condition is false, change the value to the Year.

Gary
gwinn7
 
remove the "Extra" ! (after YrID) in this line
If Forms!ORPInsForm!YrID!>1 Then

If Forms!ORPInsForm!YrID > 1 Then

PaulF
 
PaulF and Gary,
I actually did not have the "Extra" ! in my code.
Here is exactly what it looks like:

[tt]Private Sub VehicleID_Exit(Cancel As Integer)
If Forms!ORPInsForm!YrID > 1 Then YrID
Else: YrID = Year(Date)
End Sub
[/tt]

The error message reads:
Invalid use of property

It appears as thow the YRID field property needs to be changed. Currently it's data type is a NUMBER the format is FIXED and decimal places set a O. Any suggestions to make this work?

Thanks, Bill

 
Try this (assuming that Forms!ORPInsForm is open while you perform this code)
Private Sub VehicleID_Exit(Cancel As Integer)
If Forms!ORPInsForm!YrID > 1 Then
Me.YrID = Forms!ORPInsForm!YrID
Else
Me.YrID = Year(Date)
End If
End Sub

if you still have problems, you may need to use CLng, CDbl or CSng to convert the year from a Date/Time type to Long, Double or Single as appropriate.
PaulF
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top