Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Change a Labels Caption 1

Status
Not open for further replies.

straydog

Technical User
Aug 3, 2002
6
US
In Access 2000 I am trying to change the caption of a label through code after the click event of a button control until the next time I open the form and click the button again. I tried the below but each time I close and reopen the form the change is lost.

Me.lblLastApproved.Caption = "Approved: " & Date

thanks much for your help
Pdeeney
 
Put your code behind the OnOpen event of the form. This will make it be applied whenever the form is opened. Cheers,

Steve Lewy
Solutions Developer
steve@lewycomputing.com.au
 
If you make changes to a labels caption using code the changes will not be saved. As soon as you close the form the labels caption will revert back to what you set it to in design view.

To do what you want you will need to store the status of Approved in the table that the form is bound to if you are not already doing this. I would use a Yes/No field and would call it Approved. Place a checkbox on the form and name it cboApproved and bind it to the Approved field. In the AfterUpdate event of the checkbox put the following code.

Private Sub cboApproved_AfterUpdate()
If Me.cboApproved = true then
Me.lblLastApproved.Caption = "Approved: " & Date
Else
Me.lblLastApproved.Caption = "What ever you want it to say"
End If
End Sub

You do not realy need the button at all and by using the checkbox you can always uncheck it if tou need to.

Then in the OnCurrent event of the form place the following code. It is best to put it in the OnCurrent event. That way the label will update if the user moves to a different record while the form is open.

Private Sub Form_Current()
If Me.cboApproved = true then
Me.lblLastApproved.Caption = "Approved: " & Date
Else
Me.lblLastApproved.Caption = "What ever you want it to say"
End If
End Sub

This will update the label each time a record is displayed with the correct caption depending on the value of the Approved field.

I hope this helps.

Dermot




 
Many thanks for the responses.

I have a difficult time trying to communicate my problem without going into a lengthy post.

Laois: Your suggestion was very close to what I am trying to accomplish and lead me right to the solution I needed.

Once again thankyou both for your suggestions.

PDeeney
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top