General discussion

Locked

VB for Access 2003

By tjessee ·
I have the following code in a module:

Private Sub Detail_Click()
If Termed.Value = True Then
TermLabel.Caption = "Terminated"
End If
End Sub

The problem is that it won't display the Terminated sign unless you click on the page some where. I would like for it to Populate as soon as the form page loads. It also doesn't clear out if the next record isn't a terminated employee. I am not to familiar with VB so any help is truly appreciated.

This conversation is currently closed to new comments.

12 total posts (Page 1 of 2)   01 | 02   Next
| Thread display: Collapse - | Expand +

All Comments

Collapse -

by Tink! In reply to VB for Access 2003

If you want it to run as soon as the form page loads, place your code in the "On Load" event for the form instead of "On Click".

As for the other part...clearing in the next record if not terminated...you need to choose how you want it done.

If you keep the code in the Form properties (so it runs when the form loads) you'll need to put in a Next Record reference until it reaches the end of record to refresh all the records. Right now it runs once on the current record and doesn't know to check all records
I do not know how to do this right now, but if I get some time later I'll check it out for you.

Or you can place the code in a field on the records. Probably a "Got Focus" event on the first field so that when you go to that record, the code will run as soon as the cursor is in that field.

Let me know if you need clarification.
Tink

Collapse -

by Tink! In reply to

Ok, I reread your prob and I realized you were changing a label. Labels will be constant throughout the database just like a field is. (if you change a format of a field, say the background color, it changes that field throughout the DB)

Therefore if you want a record dependent display, change the Label to a text field and the change the "value" of the field instead of the "caption".

Also, put this code in the "Got Focus" event of the very first field in your form.

Collapse -

by tjessee In reply to

Poster rated this answer.

Collapse -

by tjessee In reply to VB for Access 2003

Tink,

Thank you very much for the input. I tried changing it to an On_Load() but it didn't change the label. I do very much appreciate the effort.

Troy

Collapse -

by stephen.burns In reply to VB for Access 2003

You need to move the code to the Form_Current event so it runs every time you load/change records. Then you need to set the value to what you want it to be for each record. The label will not return to its original value unless you close the form.

The context could also help. put "Me." infront of the field references.

Private Sub Form_Current()
If Termed.Value = True Then
me.TermLabel.Caption = "Terminated"
else
me.TermLabel.Caption = ""
End If
End Sub

Collapse -

by tjessee In reply to

Poster rated this answer.

Collapse -

by psomoorthi In reply to VB for Access 2003

Try the same with Form_current()
It should come as
Private sub Form_current()
If termed.value = true then
termlabel.caption = "Terminated"
end if
end sub

It works when ur navigator button clicked for record navigation.

P.Somoorthi.

Collapse -

by tjessee In reply to

Poster rated this answer.

Collapse -

by tjessee In reply to VB for Access 2003

Thank you Tink, Topaz and psomoorthi, by combining all of your tips, I was able to get it to work perfectly. This was the final code that worked.

Private Sub Form_current()
If Termed.Value = True Then
TermLabel.Caption = "Terminated"
Else
TermLabel.Caption = ""
End If
End Sub

Collapse -

by Tillworks In reply to VB for Access 2003

I've also had trouble with getting the Caption property to render immediately. Sometimes I need to call the Repaint method of the form container object.

Back to Web Development Forum
12 total posts (Page 1 of 2)   01 | 02   Next

Related Discussions

Related Forums