Combining codes

  • Thread starter Thread starter ladybug via AccessMonster.com
  • Start date Start date
L

ladybug via AccessMonster.com

I have this code in a Before Update on a form:
If Not IsNull(Me.[Client]) And (IsNull(Me.[hours]) Or Me.[hours] = 0) Then
MsgBox "Field hours must be updated"
Cancel = True ' will stop the process
End If

I now need another field required if the Client field is selected. It is not
a number field.
I figured something like this:
If Not IsNull(Me.[Client]) And (IsNull(Me.[origin]) Or Me.[origin] = Null)
Then
MsgBox "Origin must be selected"
Cancel = True ' will stop the proces
End If

How do I combine both of these codes? I keep receiving an error.
 
Hi

Use...

If (Not IsNull(Me.[Client])) And (IsNull(Me.[origin]) Or Me.[origin] = "")
Then
MsgBox "Origin must be selected"
Cancel = True ' will stop the proces
End If

Alternatively, use the Nz function
If arg is null then Nz(arg, val) returns val
If arg is not null then Nz(arg, val) returns arg

So you can use...

If Not IsNull(Me.[Client]) Then
If Nz(Me.[hours],0) = 0 Then
MsgBox "Field hours must be updated"
Cancel = True ' will stop the process
ElseIf Nz(Me.[origin],"") = "" Then
MsgBox "Origin must be selected"
Cancel = True ' will stop the proces
End If
End If


Regards

Andy Hull
 
Thank you! It works wonderfully!

Andy said:
Hi

Use...

If (Not IsNull(Me.[Client])) And (IsNull(Me.[origin]) Or Me.[origin] = "")
Then
MsgBox "Origin must be selected"
Cancel = True ' will stop the proces
End If

Alternatively, use the Nz function
If arg is null then Nz(arg, val) returns val
If arg is not null then Nz(arg, val) returns arg

So you can use...

If Not IsNull(Me.[Client]) Then
If Nz(Me.[hours],0) = 0 Then
MsgBox "Field hours must be updated"
Cancel = True ' will stop the process
ElseIf Nz(Me.[origin],"") = "" Then
MsgBox "Origin must be selected"
Cancel = True ' will stop the proces
End If
End If

Regards

Andy Hull
I have this code in a Before Update on a form:
If Not IsNull(Me.[Client]) And (IsNull(Me.[hours]) Or Me.[hours] = 0) Then
[quoted text clipped - 12 lines]
How do I combine both of these codes? I keep receiving an error.
 
Back
Top