Visual Basic question for if then statement

K

Keri

Hi I am trying to write a code using the if then statment. I am tracking
mileage costs for cars but I need to add a statement if the car was only used
for a number of days to get it charge the monthly fee right. Here is the
code that I'm using

Private Sub Monthly_Rental_BeforeUpdate(Cancel As Integer)
If Days < 30 Then
If IsNull(Me.Day_Rates) Then
Me.Day_Rates = Monnthly_Rental / Days
End If
End If
End Sub

Its not working proberly and I not sure what I'm doing wrong. Thank you.
 
G

Graham Mandeno

Hi Keri

I'm not quite clear about what you are trying to achieve, and why it is not
working.

However, if you want to calculate a pro-rata rate for Days as a fraction of
the whole month, you need something like this:

Me.Day_Rates = Monthly_Rental * Days / 30
 
L

Linq Adams via AccessMonster.com

Me.Day_Rates = Monnthly_Rental / Days

Of course the problem could be that you've simply misspelled one of your
object names! Perhaps

Monnthly_Rental

should be

Monthly_Rental
 
G

Graham Mandeno

LOL! Yes, I noticed that, Linq, but the possibility was too much to
contemplate <g>
 
K

Keri

Hi Linq and Graham,

Thank you very much for your response. I was able to get the epression
bulider to work with the function that Graham gave me but the code didn't
work. I tried it before and after update. I guess I need to take a detailed
class on Visual Basic. I really like the programming but I get fustrated
when what I think would be simple doesn't work the way it should.

Keri
 

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