Changing BackColor

S

Sash

I have the following code (just a snippet, test other fields the same way) to
change the color of incomplete fields on a continuous form. My issue is that
the user can move to the next record without fixing the prior and if they
leave a different field blank that changes all the forms for that field to
red and you loose whatever what highlighted on the prior. Is there someway
to not allow them to enter a new record until complete? Oh and this code is
executed "After Insert"

Dim lgRed As Long
lgRed = RGB(255, 64, 64)

If IsNull(Item_Number) Then
MsgBox "Please Complete Item Number"
Me!Item_Number.BackColor = lgRed
End If
 
L

Linq Adams via AccessMonster.com

On Continuous or Datasheet forms, this kind of formatting can only be done
thru Conditional Formatting from the menu, not thru code.

Your code needs to be in the Form_BeforeUpdate event in order for it to stop
the user from moving to the next record without correcting the deficit..
You'd need something like:

If IsNull(Item_Number) Then
MsgBox "Please Complete Item Number"
Cancel = True
Me!Item_Number.SetFocus
End If
 
L

Linq Adams via AccessMonster.com

Actually, I prefer

If IsNull(Me.Item_Number) Then
MsgBox "Please Complete Item Number"
Cancel = True
Me!Item_Number.SetFocus
End If
 
D

DaveT

Don't forget that you can always just use one of the eight VBA color
constants such as vbBlack, vbRed, vbGreen, vbYellow, vbBlue, vbMagenta,
vbCyan, vbWhite

ctrlTxt.Backcolor = vbRed
 
Top