Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 300
  • Last Modified:

Using an If statement in VBA to change the value of a field

Hello, I have a form (frmDecisionTree) with several Yes/No field types as check boxes.  
I want three of these fields PPopulation DDesign1 and D2Design2 to control the result of a field called NDE.  If all three of these are unchecked then I want it to record NDE.  If that isn't the case then I want the value to be null.  Can anyone help with the syntax of this and let me know if I should be using afterupdate?

Thank you,
Bevo


Private Sub NDE_AfterUpdate()
If qryDecisionTree.[PPopulation] Is False And qryDecisionTree.[DDesign1] Is False And qryDecisionTree.[D2Design2] Is False Then qryDecisionTree.NDE = NDE Else NDE Is Null
End Sub

Open in new window

0
Bevos
Asked:
Bevos
  • 2
1 Solution
 
Dymer2Commented:
Hi.
Im not sure of what NDE is, but here what I can figure out.
Put a call to a Sub in each of the checkboxes Click Event. The Sub itself could look like this:
/Dymer

Private Sub Calc_NDE()
If qryDecisionTree.[PPopulation] Or qryDecisionTree.[DDesign1] Or qryDecisionTree.[D2Design2] Then 
qryDecisionTree.NDE Is Null
Else
qryDecisionTree.NDE = NDE 
End If
End Sub

Open in new window

0
 
BevosAuthor Commented:
Hi Dymer, this isn't working.  Maybe if you take a look at the form it would be easier to understand than me trying to explain it.  The form is frmDecisionTree.

Thanks,
Bevo


EE-example-2-.accdb
0
 
GrahamSkanRetiredCommented:
It isn't clear why you have a form called qryDecisionTree as well as frmDecisionTree.

Try it like this:
Private Sub Calc_NDE()
    If Me.[PPopulation] And Me.[DDesign1] And Me.[D2Design2] Then
        Me.NDE = Null
    Else
        Me.NDE = NDE
    End If
End Sub

Private Sub NDE_AfterUpdate()
    Calc_NDE
End Sub

Open in new window

0
 
BevosAuthor Commented:
qryDecisionTree is the control source of frmDecisionTree.  I tried your code and couldn't get it to work (field NDE remains untouched)
The field NDE is just blank and should be autocalculated based on the selections in the check boxes so I don't think the 'after update' should be applied to it
I tried putting this in the afterupdate of some of the check boxes but that didn't work either.

Any ideas?

Thanks so much,
Bevo
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now