Is it possible to have the text "caption" come from the table?

  • Thread starter Thread starter Gary
  • Start date Start date
G

Gary

I want to have the button labels text to change according to the information
in the record.

How can I do that?

I posted this question to the wrong news group and was not clear.



I have a table that is telemarketing tree.

Each record has 2-4 answers that I want to be buttons. The button names in
the database and I want each button to cause a specific record to repopulate
the form with it's info.



Is it possible to have the text "caption" come from the table?
 
Gary said:
I want to have the button labels text to change according to the
information in the record.

How can I do that?

I posted this question to the wrong news group and was not clear.



I have a table that is telemarketing tree.

Each record has 2-4 answers that I want to be buttons. The button
names in the database and I want each button to cause a specific
record to repopulate the form with it's info.



Is it possible to have the text "caption" come from the table?

Sure. You would use code in the form's Current event to look up the
text for the button captions, and then set each button's Caption
property to the appropriate text. For example,

Me.cmdButton1.Caption = _
DLookup("Answer1", "tblAnswers", QuestionID=" & Me.QuestionID)

or something roughly along those lines.
 
Thsnks. I have not done anything with access for 5 years so could you
explain in more detail how to do it.

The table
ID
Purpose
Title
Script
Question
Choice-1_ID
Choice-1_Description
Choice-2_ID
Choice-2_Description
Choice-3_ID
Choice-3_Description
Choice-4_ID
Choice-4_Description



The form is scritp.

Thanks
 
Gary said:
Thsnks. I have not done anything with access for 5 years so could you
explain in more detail how to do it.

The table
ID
Purpose
Title
Script
Question
Choice-1_ID
Choice-1_Description
Choice-2_ID
Choice-2_Description
Choice-3_ID
Choice-3_Description
Choice-4_ID
Choice-4_Description



The form is scritp.

Thanks

I'm not sure I have the complete picture, but I'll try to give you the
idea. As I understand it, the form is based on the table whose fields
you listed. Command buttons on the form correspond to the 4 "choice"
field-pairs in the record. For each record, you want the captions of
the command buttons to take on the values of the corresponding
"Choice-n_Description" fields from that record. I'm going to take this
a step further and guess that, since not all questions have 4 choices,
some of those "Choice-n_ID" fields may be Nul, and if they are, you
don't want those buttons to show on the form at all.

What I propose will only work if the form is in single-form view, not
continuous-forms view. So only one record will be visible at a time.

Let's name the buttons cmdChoice1, cmdChoice2, cmdChoice3, and
cmdChoice4, to correspond numerically with the four "Choice-n" field
pairs in the record. Then we could write an event procedure for the
form's Current event like this:

'----- start of event procedure (AIR CODE) -----
Private Sub Form_Current()

Dim intChoice As Integer

For intChoice = 1 to 4

If IsNull(Me.Controls("Choice-" & intChoice & "_ID")) Then
' This choice is not available, so hide the button for it.
Me.Controls("cmdChoice" & intChoice).Visible = False
Else
With Me.Controls("cmdChoice" & intChoice)
' Set the caption for the corresponding button.
.Caption = _
Me.Controls("Choice-" & intChoice & "_Description")
' Show the button.
.Visible = True
End With
End If

Next intChoice

End Sub
'----- end of event procedure -----

If I've guessed right about what you want, that should give you
something close to it.
 
Thanks


Dirk Goldgar said:
I'm not sure I have the complete picture, but I'll try to give you the
idea. As I understand it, the form is based on the table whose fields
you listed. Command buttons on the form correspond to the 4 "choice"
field-pairs in the record. For each record, you want the captions of
the command buttons to take on the values of the corresponding
"Choice-n_Description" fields from that record. I'm going to take this
a step further and guess that, since not all questions have 4 choices,
some of those "Choice-n_ID" fields may be Nul, and if they are, you
don't want those buttons to show on the form at all.

What I propose will only work if the form is in single-form view, not
continuous-forms view. So only one record will be visible at a time.

Let's name the buttons cmdChoice1, cmdChoice2, cmdChoice3, and
cmdChoice4, to correspond numerically with the four "Choice-n" field
pairs in the record. Then we could write an event procedure for the
form's Current event like this:

'----- start of event procedure (AIR CODE) -----
Private Sub Form_Current()

Dim intChoice As Integer

For intChoice = 1 to 4

If IsNull(Me.Controls("Choice-" & intChoice & "_ID")) Then
' This choice is not available, so hide the button for it.
Me.Controls("cmdChoice" & intChoice).Visible = False
Else
With Me.Controls("cmdChoice" & intChoice)
' Set the caption for the corresponding button.
.Caption = _
Me.Controls("Choice-" & intChoice & "_Description")
' Show the button.
.Visible = True
End With
End If

Next intChoice

End Sub
'----- end of event procedure -----

If I've guessed right about what you want, that should give you
something close to it.

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

(please reply to the newsgroup)
 
Back
Top