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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to Bind combo box to primary key but display a description field u

Status
Not open for further replies.

lianghua19

Programmer
Jun 13, 2011
1
US
Default how to Bind combo box to primary key but display a description field using vba code?
Reference:
the link above shows how to manipulate it manually, but what i thought is using vba code to execute it automatically when i click a button on a form.

Here is the code what i thought, but apparently it seems there are errors in it.

Private Sub lookup()
Dim dbs As Database, tdf As TableDef
Dim fld As Field, prp As Property

Set dbs = CurrentDb
Set tdf = dbs.TableDefs(table_name)
Set fld = tdf(table_field)
Set prp = fld.CreateProperty("DisplayControl", 3, 111)
fld.Properties.Append prp
Set prp = fld.CreateProperty("Rowsource", 12, "table_query")
fld.Properties.Append prp
Set prp = fld.CreateProperty("BoundColumn", 3, 1)
fld.Properties.Append prp
Set prp = fld.CreateProperty("ColumnCount", 3, 2)
fld.Properties.Append prp
Set prp = fld.CreateProperty("ColumnHeads", False)
fld.Properties.Append prp
Set prp = fld.CreateProperty("ColumnWidth", " 0;1")
fld.Properties.Append prp
DoCmd.Close
End Sub


Thanks in advance.
Edit/Delete Message Reply With Quote Multi-Quote This Message Quick reply to this message
 
Sorry, but that code makes no sense to me, or I cannot figure out what you are trying to do. It appears you are trying to give a field custom properties for a control.
Do you just want to define the properties of a combobox? That is simply something like

Private Sub Combo0_DblClick(Cancel As Integer)
With Combo0
.RowSource = someVariable_NameOfAQuery
.controlSource = someVariable_NameOfaField
.ColumnCount = 2
.BoundColumn = 1
.ColumnHeads = True
.ColumnWidths = "0;2"
.Width = 2 * 1440 'in twips
End With
End Sub

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top