Result of code

majid.pervaiz

Registered User.
Local time
Today, 10:07
Joined
Oct 15, 2012
Messages
110
Dear All,

I have 2 text boxes Agreed SLA which is automatically computed and not getting stored in database and another box total time which is saving in database.
I am trying to compare both and see whether SLA is met or not with the below code but everytime it's showing SLA Not Met

If Me.SLA_Count.Value > Me.Total_Time_Taken.Value Then
MsgBox "SLA Met"
Else
MsgBox "SLA Not Met"
End If

appreciate your advise.
also if possible let me know how to save computed values to database.

I am completely new to access your support is required.

many thanks
 
I have also tested by just showing a message box to see the value example below

MsgBox "Value " & Me.SLA_Count.Value

MsgBox "Value " & Me.Total_Time_Taken.Value

it was showing the correct value, however, when I am comparing it is not showing correctly the difference such as SLA Met or Not Met.
 
First - you don't need .Value it is the default property.
What result do you get if you do

Msgbox "Calulation " & (Me.SLA_Count - Me.Total_Time_Taken) ?
 
see the screenshot, what I need when I click on update record. it should check the value in Agreed SLA (which is calculated automatically) not saving in database. then I have Total Time Taken (it is saved in database).

I want to compare these both values and show in SLA Met Box whether SLA Met or Not. below is the thing I did.

I don't know why even the value is less but is shows SLA Not met. may be the value of Agreed SLA is not saved in database that's why. I don't know how to save calculated value in database.

If Me.TxtDuration.Value < Me.SLA_Count.Value Then
Me.SLA_Met.SetFocus
Me.SLA_Met.Text = "SLA Met"
Else
Me.SLA_Met.SetFocus

Me.SLA_Met.Text = "SLA Not Met"

End If

I would really appreciate your expert advise.
 

Attachments

  • New Picture (1).jpg
    New Picture (1).jpg
    23.1 KB · Views: 68
  • SLA Met Issue.jpg
    SLA Met Issue.jpg
    23.6 KB · Views: 70
Last edited:
More easily done in the ControlSource of the SLA_Met.

You should not be saving the calculated value in the database. Both the agreed SLA_Count and SLA_Met should be recalculated as required.

The left justification indicates TotalTimeTaken is displaying text. In text comparisons, 75 is greater than 440.
 
Hi Galaxiom - Dear If I am changing data type of TotalTimeTake it is no longer calculating. Do you suggest I change the data type of agreed SLA to text so that both will be same and then calculation should work
 
Your posts are confusing because you have changed the names between the first post and later.

How do you calculate the time taken?

You could try converting it to a number. This will convert to Long Integer.

CLng(Me.controlname)
 
If Val("0" & Me.SLA_Count.Value) > Val("0" & Me.Total_Time_Taken.Value) Then
MsgBox "SLA Met"
Else
MsgBox "SLA Not Met"
End If
 
If Val("0" & Me.SLA_Count.Value) > Val("0" & Me.Total_Time_Taken.Value) Then

Yes that will work too but Val() is a more complex function.

It must iterate though a string to find the first non-numeric expression. Then it determine the correct format of the output based on the numeric structure.

CInt(), CLng() and CDbl() get right to the conversion. In the context of the OP, the expression appears to be an integer. I went for Long because the difference between Integer and Long in notional in a 32 bit environment. Even if the input contained a period, Lng() would simply round it for numbers up to two billion or so.

BTW All these functions, including Val() accept strings that express exponential notation. So be careful when you use Val() to extract the numbers from the start of the string.

Code:
Val("5e2sometext") = 500

The letter "n" also represents the exponent marker. I have always wondered why. The "e" I was taught at school but I have never encountered "n" anywhere outside of this context.
 
I'm sure we used n as a "to the power of" notation, but education was a long time ago... ;)
 

Users who are viewing this thread

Back
Top Bottom