Form Button - Caption = Form Variable

T

The Boondock Saint

Is there a way to make the Caption of a button the same as a variable in the
form....

for example i have a field called team1

and id like to be able to have a button that has team1's data as the caption
of the button..

Any ideas? for office 2000
 
D

Dirk Goldgar

The Boondock Saint said:
Is there a way to make the Caption of a button the same as a variable
in the form....

for example i have a field called team1

and id like to be able to have a button that has team1's data as the
caption of the button..

Any ideas? for office 2000

You could use code in the form's Current event and the "Team1" control's
AfterUpdate event to make this happen. For each event you'd need to
create an event procedure, each of which would execute the statement

Me!YourButtonName.Caption = Me!Team1

(substituting the appropriate names of the controls for "YourButtonName"
and "Team1", of course).
 
T

The Boondock Saint

Thanks for the advice Dirk,
Could you help me understand abit more about where this should go.. so that
it happens as soon as the record loads...
You said Current Event, where about can i find this.... and Event
Procedure....

Thanks for your help..
The Saint
 
D

Dirk Goldgar

The Boondock Saint said:
Thanks for the advice Dirk,
Could you help me understand abit more about where this should go..
so that it happens as soon as the record loads...
You said Current Event, where about can i find this.... and Event
Procedure....

Thanks for your help..
The Saint

Here's how you do it. In these instructsions, I'm going to continue to
use "YourButtonName" and "Team1" as the names of the controls, but
you'll need to put the real names in.

Open the form in Design View.

Open the property sheet of the form (by clicking the Properties button
on the toolbar, or menu item View -> Properties).

Go to the Event tab on the property sheet. The first event property
listed is On Current. Double-click on the blank line beside the
property name.

If the line doesn't change to say "[Event Procedure]", click the
dropdown arrow that will have appeared at the right of the line, and
choose "[Event Procedure]" from the list.

Then click the "build" button -- caption "..." -- that appears to the
right of the dropdown arrow. The VB Editor window will open (separate
from the Access application window), with a window for the form's code
module inside it and the shell of an event procedure already created and
displayed for you. It will look like this:

Private Sub Form_Current()

End Sub

Change that procedure to look like this (subsitituting the appropriate
names):

Private Sub Form_Current()

Me!YourButtonName.Caption = Me!Team1

End Sub

That takes care of the form's Current event. We also need to create
procedure for the AfterUpdate event of the Team1 control.

Switch back to the Access application window. You don't need to close
the VB Editor window.

Looking at the form in design view, click on the "Team1" control. If
the property sheet is still open, it will automatically change from
displaying the form's property sheet to displaying the property sheet
for Team1. If the property sheet isn't open, open it.

On the Event tab of the property sheet, go down to the After Update
event property line (the second line from the top, I think). Follow a
similar procedure to the one you used for the On Current property, to
create and display an event procedure shell for this event. It will
look like this:

Private Sub Team1_AfterUpdate()

End Sub

Change that procedure to look like this (subsitituting the appropriate
names):

Private Sub Team1_AfterUpdate()

Me!YourButtonName.Caption = Me!Team1

End Sub

Having done that, close the module window, then click the Save button on
the toolbar of the VB Editor, and close the VB Editor. That should drop
you back in the regular Access application window. Close the form,
saving it if prompted to do so.

You're done. Try it and see if it works. If it doesn't, we've probably
got the names of the controls wrong.
 
T

The Boondock Saint

Thank you very much Dirk.

Your instructions were awesome.. im only new to this side of Access... but
everything you wrote was logical and easy for me to follow... thanks once
again for taking the time out to help me.

Thanks
The Saint
Dirk Goldgar said:
The Boondock Saint said:
Thanks for the advice Dirk,
Could you help me understand abit more about where this should go..
so that it happens as soon as the record loads...
You said Current Event, where about can i find this.... and Event
Procedure....

Thanks for your help..
The Saint

Here's how you do it. In these instructsions, I'm going to continue to
use "YourButtonName" and "Team1" as the names of the controls, but
you'll need to put the real names in.

Open the form in Design View.

Open the property sheet of the form (by clicking the Properties button
on the toolbar, or menu item View -> Properties).

Go to the Event tab on the property sheet. The first event property
listed is On Current. Double-click on the blank line beside the
property name.

If the line doesn't change to say "[Event Procedure]", click the
dropdown arrow that will have appeared at the right of the line, and
choose "[Event Procedure]" from the list.

Then click the "build" button -- caption "..." -- that appears to the
right of the dropdown arrow. The VB Editor window will open (separate
from the Access application window), with a window for the form's code
module inside it and the shell of an event procedure already created and
displayed for you. It will look like this:

Private Sub Form_Current()

End Sub

Change that procedure to look like this (subsitituting the appropriate
names):

Private Sub Form_Current()

Me!YourButtonName.Caption = Me!Team1

End Sub

That takes care of the form's Current event. We also need to create
procedure for the AfterUpdate event of the Team1 control.

Switch back to the Access application window. You don't need to close
the VB Editor window.

Looking at the form in design view, click on the "Team1" control. If
the property sheet is still open, it will automatically change from
displaying the form's property sheet to displaying the property sheet
for Team1. If the property sheet isn't open, open it.

On the Event tab of the property sheet, go down to the After Update
event property line (the second line from the top, I think). Follow a
similar procedure to the one you used for the On Current property, to
create and display an event procedure shell for this event. It will
look like this:

Private Sub Team1_AfterUpdate()

End Sub

Change that procedure to look like this (subsitituting the appropriate
names):

Private Sub Team1_AfterUpdate()

Me!YourButtonName.Caption = Me!Team1

End Sub

Having done that, close the module window, then click the Save button on
the toolbar of the VB Editor, and close the VB Editor. That should drop
you back in the regular Access application window. Close the form,
saving it if prompted to do so.

You're done. Try it and see if it works. If it doesn't, we've probably
got the names of the controls wrong.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 

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