Sub CreateField(strTable As String, strField As String, strsql As String)
Dim MyDB As Database
Dim MyTbl As TableDef
Dim MyField As DAO.Field
Set MyDB = CurrentDb
Set MyTbl = MyDB.TableDefs(strTable)
Set MyField = MyTbl.CreateField(strField, dbLong)
MyTbl.Fields.Append MyField
MyField.Properties("DisplayControl") = 111 'The "111" value converts to a combo box
MyField.Properties("RowSourceType") = "Table/Query"
'The properties below don't exist until the Display Control is changed to a combo box. But the added properties "RowSource", "ComolumCount" and
'"ColumnWidths" do not magically appear after I've changed DisplayControl to "111".
MyField.Properties("RowSource") = strsql
MyField.Properties("ColumnCount") = 2
MyField.Properties("ColumnWidths") = "0;1440"
End Sub
ChangeDisplayControl.bmp
ASKER
Microsoft Access is a rapid application development (RAD) relational database tool. Access can be used for both desktop and web-based applications, and uses VBA (Visual Basic for Applications) as its coding language.
TRUSTED BY
See here:
http://access.mvps.org/access/lookupfields.htm
Creating a combobox on the "form" is fine though.
Creating/Modifying Controls at runtime decompiles your application, so you have to have to be very disciplined in compiling your code, saving your objects and running the compact/repair utility...
This is probably the reason for your issue here.
At runtime, the change is not "Logged" into the DB until the internal structure is refreshed,
...Either by saving the object, or running the Compact/Repair utility, or compiling the code.
So it is best to do all three to be on the safe side.
Can you state the "Why" behind this approach, ...in case there is a more standardized way of achieving this?
JeffCoachman