updated field

F

fishqqq

Can someone tell me what the expression would be to have a field
automatically update itself based on the value of another field?

I want to have a form that automatically inputs a tax code if the
$amount in the record is taxable.

[field1] = tax amt for the record
[field2] = tax code for the record

in the after focus event of [field1] i'd like the application to do
the following

if [field1] = $0.00 then set value of [field2] = null (leave blank)
if [field1] is not null then set value of [field2] to "H" (which is
the tax code for HST)

Can someone tell me how i would express this correctly?

thanks
Steve
 
F

fishqqq

Use code in the AfterUpdate event of the textbox. This is untested:

Private Sub Field1_AfterUpdate()
    If Field1 = 0 OR IsNull(Field1) Then
        Field2 = Null
    Else
        Field2 = "H"
    End If
End Sub
--
Arvin Meyer, MCP, MVPhttp://www.datastrat.comhttp://www.accessmvp.comhttp://access.mvps.org
Co-author: "Access Solutions", published by Wiley








Can someone tell me what the expression would be to have a field
automatically update itself based on the value of another field?
I want to have a form that automatically inputs a tax code if the
$amount in the record is taxable.
[field1] = tax amt for the record
[field2] = tax code for the record
in the after focus event of [field1] i'd like the application to do
the following
if [field1] = $0.00 then set value of [field2] = null (leave blank)
if [field1] is not null then set value of [field2] to "H"  (which is
the tax code for HST)
Can someone tell me how i would express this correctly?
thanks
Steve

Thanks Arvin, usually i don't have much success with code - i prefer
to work with macros etc but in this case i was able to get your
suggestion to work perfectly - thanks again.
The afterupdate property of this field is already set with a macro
that updates a field

setvalue:
item: [Forms]![fExpRptViewPrevious]![fExpListView Previous].[Form]!
[HST]
expression: [Forms]![fExpRptViewPrevious]![fExpListView Previous].
[Form]![Amount]*0.13


So now i have to somehow have the afterupdate field do the above
setvalue function FIRST then run your suggested code SECOND so that
the action is complete.

Can you please suggest how i would combine the two?

below is the code you provided with the correct field names:

Private Sub Text18_AfterUpdate()

If HST = 0 Or IsNull(HST) Then
SLS_Tax_Code = Null
Else
SLS_Tax_Code = "H"
End If
End Sub

thanks
Steve
 
A

Access Developer

There's no "After Focus" event... the "Got Focus" would fire before the
Control was updated, but "Lost Focus" would fire as the Focus moved off the
Field (but would fire whether the data in the Control was actually updated
or not -- in this case it wouldn't matter, except for wasting a miniscule
amount of compute time). But, I'd caution you that "focus" events aren't as
reliable as "update" events. If you could/would convert the macro to VBA
code, you could handle it all in the After Update event. And a macro that
updates the value in a Control or a Field in the Record Source should be
very simple to convert.

"Nobody's ferpect," they say, but if Arvin tells you something about Access,
you can "take it to the bank". I've known him electronically for a long
time, and in person for nearly ten years, and he "knows his stuff".

--
Larry Linson, Microsoft Office Access MVP
Co-author: "Microsoft Access Small Business Solutions", published by Wiley
Access newsgroup support is alive and well in USENET
comp.databases.ms-access


Use code in the AfterUpdate event of the textbox. This is untested:

Private Sub Field1_AfterUpdate()
If Field1 = 0 OR IsNull(Field1) Then
Field2 = Null
Else
Field2 = "H"
End If
End Sub
--
Arvin Meyer, MCP,
MVPhttp://www.datastrat.comhttp://www.accessmvp.comhttp://access.mvps.org
Co-author: "Access Solutions", published by Wiley








Can someone tell me what the expression would be to have a field
automatically update itself based on the value of another field?
I want to have a form that automatically inputs a tax code if the
$amount in the record is taxable.
[field1] = tax amt for the record
[field2] = tax code for the record
in the after focus event of [field1] i'd like the application to do
the following
if [field1] = $0.00 then set value of [field2] = null (leave blank)
if [field1] is not null then set value of [field2] to "H" (which is
the tax code for HST)
Can someone tell me how i would express this correctly?
thanks
Steve

Thanks Arvin, usually i don't have much success with code - i prefer
to work with macros etc but in this case i was able to get your
suggestion to work perfectly - thanks again.
The afterupdate property of this field is already set with a macro
that updates a field

setvalue:
item: [Forms]![fExpRptViewPrevious]![fExpListView Previous].[Form]!
[HST]
expression: [Forms]![fExpRptViewPrevious]![fExpListView Previous].
[Form]![Amount]*0.13


So now i have to somehow have the afterupdate field do the above
setvalue function FIRST then run your suggested code SECOND so that
the action is complete.

Can you please suggest how i would combine the two?

below is the code you provided with the correct field names:

Private Sub Text18_AfterUpdate()

If HST = 0 Or IsNull(HST) Then
SLS_Tax_Code = Null
Else
SLS_Tax_Code = "H"
End If
End Sub

thanks
Steve
 
F

fishqqq

Thanks Arvin, usually i don't have much success with code - i prefer
to work with macros etc but in this case i was able to get your
suggestion to work perfectly - thanks again.
The afterupdate property of this field is already set with a macro
that updates a field

setvalue:
item: [Forms]![fExpRptViewPrevious]![fExpListView Previous].[Form]!
[HST]
expression: [Forms]![fExpRptViewPrevious]![fExpListView Previous].
[Form]![Amount]*0.13

So now i have to somehow have the afterupdate field do the above
setvalue function FIRST then run your suggested code SECOND so that
the action is complete.

Can you please suggest how i would combine the two?

below is the code you provided with the correct field names:

Private Sub Text18_AfterUpdate()

    If Len([Amount] & vbNullString) = 0 Then
        [HST] = [Amount]*0.13
    End If

    If HST = 0 Or IsNull(HST) Then
        SLS_Tax_Code = Null
    Else
        SLS_Tax_Code = "H"
    End If
End Sub

What that does is check to see if there is a value in Amount, and multiple
it by 0.13 if there is. You could also throw up an error message if thereis
no value:

    If Len([Amount] & vbNullString) = 0 Then
        [HST] = [Amount]*0.13
    Else
        MsgBox "Please add a value to Amount", vbOKOnly
    End If




it took a bit but i got this working nicely - thanks guys!
 

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