Autofilling a field if a previous field is > 9999

D

DMainland

I use a form in a database with a field for 'gross amount'. I would like a
subsequent field on the same form to fill with that gross amount if the
number is greater than 9999. What code and location for the code would
accomplish this task?
 
S

sparker

D,

You could accomplish this in several ways depending on how you want it to
happen.
Is this field on a continuous form or not? If it is a continous form then
you could simply perform the calc in your form record source by creating a
new column that feeds the new form field also note that this would also work
if it is not a continous form... such as set your new column value as
MyNewFieldValue: IIF([TheOtherFieldName]>9999,[TheOtherFieldName],"")
As you can see above we have used the IIF statement to determine if the
other field is greater than 9999 if it is then our new column will also
contain the same value however, if it is not greater than 9999 it will
contain a zero length string = nothing. Does this value only need to be
calculated upon initial opening of the form? If so you could have the form on
open event perform the same calculation and then assign the value to the form
field you want to display it in.
 
D

DMainland

I think the form in question is not a continuous form so I would like to use
the IIF statement you recommended. Where should I be placing the code line?
--
DMainland


sparker said:
D,

You could accomplish this in several ways depending on how you want it to
happen.
Is this field on a continuous form or not? If it is a continous form then
you could simply perform the calc in your form record source by creating a
new column that feeds the new form field also note that this would also work
if it is not a continous form... such as set your new column value as
MyNewFieldValue: IIF([TheOtherFieldName]>9999,[TheOtherFieldName],"")
As you can see above we have used the IIF statement to determine if the
other field is greater than 9999 if it is then our new column will also
contain the same value however, if it is not greater than 9999 it will
contain a zero length string = nothing. Does this value only need to be
calculated upon initial opening of the form? If so you could have the form on
open event perform the same calculation and then assign the value to the form
field you want to display it in.
--
~ SPARKER ~


DMainland said:
I use a form in a database with a field for 'gross amount'. I would like a
subsequent field on the same form to fill with that gross amount if the
number is greater than 9999. What code and location for the code would
accomplish this task?
 
S

sparker

D,

you could simply copy and paste the following behind the form with the two
fields.
Change the names txtBoxFirst & txtBoxSecond to the actual names of your two
controls and this will check (when the form opens) to see if field #1 is
greater than 9999 and if it is it will then populate the exact same value in
field #2 and if it is not greater than 9999 it will leave the second field
empty.
'__________________________________________________________
Private Sub Form_Open(Cancel As Integer)
Me.txtBoxSecond.Value = _
IIf(Me.txtBoxFirst.Value > 9999, _
Me.txtBoxFirst.Value, "")
End Sub
'__________________________________________________________
--
~ SPARKER ~


DMainland said:
I think the form in question is not a continuous form so I would like to use
the IIF statement you recommended. Where should I be placing the code line?
--
DMainland


sparker said:
D,

You could accomplish this in several ways depending on how you want it to
happen.
Is this field on a continuous form or not? If it is a continous form then
you could simply perform the calc in your form record source by creating a
new column that feeds the new form field also note that this would also work
if it is not a continous form... such as set your new column value as
MyNewFieldValue: IIF([TheOtherFieldName]>9999,[TheOtherFieldName],"")
As you can see above we have used the IIF statement to determine if the
other field is greater than 9999 if it is then our new column will also
contain the same value however, if it is not greater than 9999 it will
contain a zero length string = nothing. Does this value only need to be
calculated upon initial opening of the form? If so you could have the form on
open event perform the same calculation and then assign the value to the form
field you want to display it in.
--
~ SPARKER ~


DMainland said:
I use a form in a database with a field for 'gross amount'. I would like a
subsequent field on the same form to fill with that gross amount if the
number is greater than 9999. What code and location for the code would
accomplish this task?
 

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