Button Caption rename from field

G

Guest

Hello, I would like to change the caption of a button by looking up a value
in a text field and using that value as the button name (caption). For
example, if the Clinic is Dr Brown's clinic I have a button that takes you to
the form for that clinic, but the button is labelled (caption) "Clinic 1"
ideally I would like that button to reflect the name of the clinic eg "Dr
Brown".

Sorry the solution is hopefully simple, but when such a database only
represents 1/100th of you day job, its difficult to keep all the develeopment
knowledge in your head! Thanks for any assistance. Tim.
 
K

Keith Wilby

Timboo said:
Hello, I would like to change the caption of a button by looking up a
value
in a text field and using that value as the button name (caption). For
example, if the Clinic is Dr Brown's clinic I have a button that takes you
to
the form for that clinic, but the button is labelled (caption) "Clinic 1"
ideally I would like that button to reflect the name of the clinic eg "Dr
Brown".

Search the help for "DLookup".

Regards,
Keith.
www.keithwilby.com
 
G

Guest

Dear friend,

In the On Current Event of your form add the following code:

If Me.clinic <> "" Then
Me.Command1.Caption = Me.clinic.Value
Else
Me.Command1.Caption = ""
End If

Change clinic to your clonic's field name and command1 to your command
button name.

Each time you move to a record the caption of the command button will be
changed to the value of the clinc field. If you move to a new record then
the button's name will be null (or change it to New)

Hope this will help

George

Ο χÏήστης "Timboo" έγγÏαψε:
 
G

Guest

Thank you, will give this a try, Tim


George said:
Dear friend,

In the On Current Event of your form add the following code:

If Me.clinic <> "" Then
Me.Command1.Caption = Me.clinic.Value
Else
Me.Command1.Caption = ""
End If

Change clinic to your clonic's field name and command1 to your command
button name.

Each time you move to a record the caption of the command button will be
changed to the value of the clinc field. If you move to a new record then
the button's name will be null (or change it to New)

Hope this will help

George

Ο χÏήστης "Timboo" έγγÏαψε:
 
S

Steve Schapel

Timboo,

If the name of the doctor is in a field which is part of the form's
record source table or query, then you can use code like this on the
Current event of the form...
Me.YourButton.Caption = Me.DoctorsName

If the name is not available in the form's data, please let us know how
we can know whose name to put on the button.
 
G

Guest

Thank you all for your comments, I followed the advice and achieved the
objective, now the next... I would like the caption of a button to be
dependant upon the content of a field, so if the is blank the button caption
reads something like "please complete all the fields" alternatively the
visible property could be changed dependant on the field value.

I tried this

Private Sub Command36_GotFocus()
If ClinicID.Value = Null Then
Command36.Caption = "insert data"
End If

Where ClinicID is the field on the form with the value, and Command36 is the
button in question.which seemed logical, but perhaps not logical enough!
Any feedback would be appreciated.

Thanks Tim
 
J

John Spencer

Wrong Test.

If IsNull(ClinicID) = True Then
Command36.Caption = "Insert Data"
ELSE 'don't foget to reset the value
Command36.Caption = "Save the data" 'or whatever
END IF
 
G

Guest

John, Thank you, Tim


John Spencer said:
Wrong Test.

If IsNull(ClinicID) = True Then
Command36.Caption = "Insert Data"
ELSE 'don't foget to reset the value
Command36.Caption = "Save the data" 'or whatever
END IF
 

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