Autochange field when a checkbox is checked.

  • Thread starter Thread starter ILoveAccess via AccessMonster.com
  • Start date Start date
I

ILoveAccess via AccessMonster.com

I have two fields in a table called tblLeads:

CustCode (text)
AutoFwrd (Checkbox)

When I put a checkmark in AutoFwrd, I want CustCode to change to DP

Can you help?

Thanks!
 
You can do this in SQL Server with a table trigger, but unless I'm well
out of date, Access doesn't support triggers.

The only way to enforce this would be if you can be completely sure
that the table can only be updated through a particular form - then in
the Before_Update event of the form you can set CustCode according to
AutoFwrd.

There's a question why you'd want to do this at all, though - having
fields that depend on other fields is almost always a bad idea, as
there's a risk that one field will get updated to become inconsistent
with the other. This can make things very confusing, especially in
large datasets.

You could calculate CustCode on the fly anytime by doing a
SELECT AutoFwrd,Iif(AutoFwrd=True,"DP",[something else for False]) AS
CustCode FROM tblLeads.

going on the hunch that "if users can find a way to mess up the data,
they will", I'd advise against having fields derived from other fields
in a table.

cheers



Seb
 
I have two fields in a table called tblLeads:

CustCode (text)
AutoFwrd (Checkbox)

When I put a checkmark in AutoFwrd, I want CustCode to change to DP

Can you help?

Thanks!

Code the AfterUpdate event of the AutoFwrd control:
If Me![AutoFwrd] = -1 Then
Me![CustCode] = "DP"
End If

What do you want to happen of the check is removed?
Perhaps a better code would be:

If Me![AutoFwrd] = -1 Then
Me![CustCode] = "DP"
Else
Me![CustCode] = "What do you want if unchecked?"
End If
 
I assume you are using a form and not entering directly into the table. If
you are entering directly into the table, you will not be able to do this.
If you are using a form, use the After Update event of the check box. If the
user checks the box, it will make the value in the text box "DP". If the
user unchecks the box, it will make the value Null:

Me.txtCustCode = IIf(Me.chkAutoFwrd, "DP", Null)
 
Back
Top