Comboboxes in a form

P

PK.10987

I have just started using MS Access. I have designed some tables and forms.
The problem I'm currently facing is this.

I have stored some programme codes and programme names in a table for making
the entry process easier.

So I have a programme code field that is to be selected via a combobox. What
I want is, when I select an option in the combobox I want the corresponding
programme name to appear in a textbox just below the combobox.
 
D

Dennis

Assuming your programme code is a text item, set the control source property
of your text box to
=DLookup("[Programme Name]","YourTableName","[Programme Code] = '" &
ComboBoxName & "'")
 
B

Brendan Reynolds

PK.10987 said:
I have just started using MS Access. I have designed some tables and forms.
The problem I'm currently facing is this.

I have stored some programme codes and programme names in a table for
making
the entry process easier.

So I have a programme code field that is to be selected via a combobox.
What
I want is, when I select an option in the combobox I want the
corresponding
programme name to appear in a textbox just below the combobox.


For demonstration purposes, I've set the properties of the combo box
programmatically in the form's Load event. This isn't necessary, you can set
them in design view.

Private Sub Form_Load()

Me.cboProgrammeCode.ColumnCount = 2
Me.cboProgrammeCode.ColumnWidths = ";0"
Me.cboProgrammeCode.RowSource = "SELECT ProgrammeCode, ProgrammeName
FROM Programmes"

End Sub

Private Sub cboProgrammeCode_AfterUpdate()
Me.txtProgrammeName = Me.cboProgrammeCode.Column(1)
End Sub

The code in the Load event gives the combo box two columns, leaves the width
of the first column at the default setting, and hides the second column by
giving it a width of zero, and selects both fields from the table in the row
source of the combo box.

The code in the AfterUpdate event of the combo box copies the value of the
second, hidden column to the text box. The Column property is zero-based, so
Column(1) is the second column.
 

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