simple(?) compare problem (i.e. if x > 2 then...)

  • Thread starter Thread starter Frederique
  • Start date Start date
F

Frederique

Guest
I'm not an expert on using access and making VB codes, so
I post my question right here.

I've got a database and on a form there should be done
some simple calculations.

there are four textboxes:
1. avarage (imported from a calculation on a subform)
2. minimal (imported from a table)
3. maximal (imported from a table)
4. Status (this should be saved in table X)

the calculation I want to make is (I have written it in my
own stupid abstract language:
if (avarage > minimal and avarage < maximal)
then
status-textbox = "ok"
else "not ok"



So, if 'avaraga' is bigger then 'maximal' and smaller then 'minimal' the textbox Status should say "not ok" else "ok".

How can I write this in a visualbasic code for a event of
the textbox Status? and how can it be saved to the table
where Status is an element of?

By the way, the status should be changed everytime the
textbox Avarage changes first.
 
I can suggest something like this as a starting point, I think it may be a good idea to have a command button to perform the calculation (but of course it is up to you, oncurrent event of txtStatus may be better):

Private Sub your CommandButton_Click()

Dim average As Integer
Dim minimum As Integer
Dim maximum As Integer

maximum = txtMax.Value '
average = txtaverage.Value
minimum = txtmin.Value


If average > minimum Then
If average < maximum Then
txtStatus = "OK"
Else
txtStatus = "Not OK"
End If
Else
txtStatus = "Not OK"

End If

End Sub

HTH Rich
 
it works but brought a new problem

Thank you! It works.

But it makes some misakes. i.e.:
max = 12
min = 8

average = 11,99

Average is smaller than max (11,99 < 12) but access says it is bigger.

But when avarage = 11,498 the computer says that averages is smaller then max indeed.

The datatype of all the used fields are Numbers and the fieldsize is "single"

This is a very change problem which I do not understand. I hope somebody can help me, because the calculations which should be made should be very precise.
 
Not sure, but this could be the problem:

11,99
should it be 11.99?

I think access does not recognise a comma as a decimal point, so 11,99 is read as 1199. Therefore 1199 is greater than 12.

The comma is used to make a large number more readable (I think).

Rich
 
Try this sample from the debug window:

Max = 12
Min = 8
Average = 11.99
widget = iif(average > Max or Average < Min, "Not OK", "OK")
? widget
OK

average = 7.95
widget = iif(average > Max or Average < Min, "Not OK", "OK")
? widget
Not OK
 

Users who are viewing this thread

Back
Top Bottom