Formatting on a Field for a Single Record

  • Thread starter chris1 via AccessMonster.com
  • Start date
C

chris1 via AccessMonster.com

I have a subform with an "On Exit" Event. I would like for the exit event to
inform the user of an incorrect input and have the textbox change color.
However the field with all the records change color. I have tried looking
around but I am looking for some type of VBA code that could solve that. Here
is my On Exit VBA Code

Private Sub FieldName_Exit(Cancel as Integer)
If Me.[FieldName] < sngSomeAmount and Me.[AnotherFieldname] =
"txtCriteria" then
Me.[FieldName].BorderColor = RGB(255,0,0)
Me.[FieldName].SetFocus
Else
Me.[FieldName].BorderColor = RGB(0,0,0)
Endif

Is there some code or the appropriate expression in the Conditional
Formatting section that will only work on the field in the current record.
Thank you!
 
C

chris1 via AccessMonster.com

Svetlana - I don't understand what you wrote..??
Svetlana said:
Ο/Η chris1 via AccessMonster.com έγÏαψε:
I have a subform with an "On Exit" Event. I would like for the exit event to
inform the user of an incorrect input and have the textbox change color.
[quoted text clipped - 18 lines]
Message posted via AccessMonster.com
 
G

Guest

It sounds like your subform is in datasheet view. In data sheet view, you
don't have separate controls for each record for a field. They are all the
same control repeated as many times as the number of records in the
datasheet. If you change your form to a continuous form and use conditional
formatting, you may get it to work; however, conditional formatting is not
very smart and you may or may not get the results you want.
 
C

chris1 via AccessMonster.com

Klaatu - I am in continuous mode.. with what I have written above can it be
somehow replicated in conditional formatting , if so please provide the
syntax then or maybe other VBA code
Svetlana - I don't understand what you wrote..??
Ο/Η chris1 via AccessMonster.com έγÏαψε:
I have a subform with an "On Exit" Event. I would like for the exit event to
inform the user of an incorrect input and have the textbox change color.
[quoted text clipped - 18 lines]
Message posted via AccessMonster.com
 
S

Svetlana

You could combine conditional formatting and vba but through
conditional formating you cant change the border color of the field
instead you have the choice to change the back or fore color.

For conditional formatting the expression must be
Forms!NameOfForm!NameOfField>SomeNumber AND Forms!NameOfForm!
NameOfField2='SomeText'
and you set how you like the field being formatted.
Then on BeforeUpdate event of your form

If Me.NameOfField > SomeNumber And Me.NameDescription = "SomeText"
Then
Cancel = True
MsgBox "Wrong Entry"
Me.NameOfField.SetFocus
End If
 
C

chris1 via AccessMonster.com

Hi Svetlana,

Thank you for your response, this has helped very much.

I have another question which I am sure you can help. I have another
workaround. I thought maybe if I highlight the label above the field in a
certain color (the label is in the the form header of the subform and the
textbox is located in the detail section) and then return focus to the
textbox. However the focus doesn't go back onto the textbox but to the next
textbox in the tab order. Here is my code.

Private Sub FieldName_Exit(Cancel as Integer)
If Me.[FieldName].value < sngAmount Then
Me.[FieldName Label].forecolor = RGB(255,0,0)
Me.[FieldName].SetFocus
Else
Me.[FieldName Label].Forecolor = RGB(255,0,0)
Endif
End Sub

What am I doing wrong? Thank you again!
 
S

Svetlana

For cancel the exit you want to replace the Me.[FieldName].SetFocus
with Cancel=True
 
C

chris1 via AccessMonster.com

Hi Svetlana,

Thank you very much. It worked beautifully!

I am curious though why didn't my code with the SetFocus method work and skip
over to the next textbox? Just curious!


For cancel the exit you want to replace the Me.[FieldName].SetFocus
with Cancel=True
 
S

Svetlana

The exit event doesnt stop the focus to move to the next control, its
how the event works..
If you read the help file about exit event you will find out many
usefull details.

In your case to be sure about the correct user input as the correct
entry is dependent to another field input too its better to use the
before update event of your form.
 

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

Top