lianghua19
Programmer
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
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