colour coding validation

G

Guest

Hello

I want to change a text box to red or the text to red. It should change if
it is empty and the user selects save.

My rather simple code on the save button:

If IsNull(Me.[txtDate]) Then
MsgBox "Please enter a Date", vbOKOnly, "Missing Data"
Cancel = True
End If

Any help would be greatly appreciated.
Thanks
 
J

Jamie Richards

Maybe like this?

Private Sub cmdSave_Click()
With Me
If IsNull(.txtDate) Then
MsgBox "Please enter a Date", vbOKOnly, "Missing Data"
.Field1.BackColor = vbRed
.Field1.SetFocus
End If
End With
End Sub

In the On Current event of your form set the control colour back to whatever
is standard for you form:

Private Sub Form_Current()
Me.txtDate.BackColor = vbWhite
End Sub

Jamie
 
J

Jamie Richards

Hmm, didn't change all the field names in the example did I (Field1 instead
of txtDate)...

How about this instead?

Private Sub cmdSave_Click()
With Me
If IsNull(.txtDate) Then
MsgBox "Please enter a Date", vbOKOnly, "Missing Data"
.txtDate.BackColor = vbRed
.txtDate.SetFocus
End If
End With
End Sub


Jamie

Jamie Richards said:
Maybe like this?

Private Sub cmdSave_Click()
With Me
If IsNull(.txtDate) Then
MsgBox "Please enter a Date", vbOKOnly, "Missing Data"
.Field1.BackColor = vbRed
.Field1.SetFocus
End If
End With
End Sub

In the On Current event of your form set the control colour back to
whatever is standard for you form:

Private Sub Form_Current()
Me.txtDate.BackColor = vbWhite
End Sub

Jamie

F Jones said:
Hello

I want to change a text box to red or the text to red. It should change
if
it is empty and the user selects save.

My rather simple code on the save button:

If IsNull(Me.[txtDate]) Then
MsgBox "Please enter a Date", vbOKOnly, "Missing Data"
Cancel = True
End If

Any help would be greatly appreciated.
Thanks
 
G

Guest

That's great. thanks very much.

I will give it a try and let you know if I can't get it to work.

FJ

Jamie Richards said:
Hmm, didn't change all the field names in the example did I (Field1 instead
of txtDate)...

How about this instead?

Private Sub cmdSave_Click()
With Me
If IsNull(.txtDate) Then
MsgBox "Please enter a Date", vbOKOnly, "Missing Data"
.txtDate.BackColor = vbRed
.txtDate.SetFocus
End If
End With
End Sub


Jamie

Jamie Richards said:
Maybe like this?

Private Sub cmdSave_Click()
With Me
If IsNull(.txtDate) Then
MsgBox "Please enter a Date", vbOKOnly, "Missing Data"
.Field1.BackColor = vbRed
.Field1.SetFocus
End If
End With
End Sub

In the On Current event of your form set the control colour back to
whatever is standard for you form:

Private Sub Form_Current()
Me.txtDate.BackColor = vbWhite
End Sub

Jamie

F Jones said:
Hello

I want to change a text box to red or the text to red. It should change
if
it is empty and the user selects save.

My rather simple code on the save button:

If IsNull(Me.[txtDate]) Then
MsgBox "Please enter a Date", vbOKOnly, "Missing Data"
Cancel = True
End If

Any help would be greatly appreciated.
Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top