Sacha Walter
asked on
Update a field based on completion of other fields using VBA in Access
Hi Experts,
I am attempting to update a field such that the field Completed reads 'Yes' when 3 date fields are populated and 'No' when any one of the 3 date fields are not populated. I read that you can't test for Null values unless you convert the variable to a variant so that's what I've tried to do below.
The code below returns 'No' even when the 3 date fields are populated, what am I doing wrong?
Thanks!
Private Sub Form_AfterUpdate()
Dim vconvert As Variant
Dim vconvert2 As Variant
Dim vconvert3 As Variant
Dim BValue As Boolean
Dim BValue2 As Boolean
Dim BValue3 As Boolean
Dim sSQL As String
Dim iID As Integer
iID = Me.ID.Value
vconvert = CVar(Me.DATE_AUTHORIZED)
vconvert2 = CVar(Me.DATE_COMPLETED_FOR _RELEASE)
vconvert3 = CVar(Me.DATE_RELEASED)
BValue = IsNull("vconvert")
BValue2 = IsNull("vconvert2")
BValue3 = IsNull("vconvert3")
If BValue And BValue2 And BValue3 = False Then
sSQL = "Update Main " & _
"SET [Completed]= 'Yes' " & _
"WHERE Main.[ID] = " & iID & ";"
DoCmd.SetWarnings False
DoCmd.RunSQL (sSQL)
Else
sSQL = "Update Main " & _
"SET [Completed]= 'No' " & _
"WHERE Main.[ID] = " & iID & ";"
DoCmd.SetWarnings False
DoCmd.RunSQL (sSQL)
End If
End Sub
I am attempting to update a field such that the field Completed reads 'Yes' when 3 date fields are populated and 'No' when any one of the 3 date fields are not populated. I read that you can't test for Null values unless you convert the variable to a variant so that's what I've tried to do below.
The code below returns 'No' even when the 3 date fields are populated, what am I doing wrong?
Thanks!
Private Sub Form_AfterUpdate()
Dim vconvert As Variant
Dim vconvert2 As Variant
Dim vconvert3 As Variant
Dim BValue As Boolean
Dim BValue2 As Boolean
Dim BValue3 As Boolean
Dim sSQL As String
Dim iID As Integer
iID = Me.ID.Value
vconvert = CVar(Me.DATE_AUTHORIZED)
vconvert2 = CVar(Me.DATE_COMPLETED_FOR
vconvert3 = CVar(Me.DATE_RELEASED)
BValue = IsNull("vconvert")
BValue2 = IsNull("vconvert2")
BValue3 = IsNull("vconvert3")
If BValue And BValue2 And BValue3 = False Then
sSQL = "Update Main " & _
"SET [Completed]= 'Yes' " & _
"WHERE Main.[ID] = " & iID & ";"
DoCmd.SetWarnings False
DoCmd.RunSQL (sSQL)
Else
sSQL = "Update Main " & _
"SET [Completed]= 'No' " & _
"WHERE Main.[ID] = " & iID & ";"
DoCmd.SetWarnings False
DoCmd.RunSQL (sSQL)
End If
End Sub
I agree with above.
Just time highlight the issue in your code:
= IsNull("vconvert")
Should be:
= IsNull(vconvert)
Just time highlight the issue in your code:
= IsNull("vconvert")
Should be:
= IsNull(vconvert)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Update Main
Set [Completed]=IIf([DATE_AUTH
.