frothytoad
Technical User
Hello all,
I have been running into two problems that have me completely stumped, and I am hoping someone can offer an answer for one or both.
The first has to do with creating controls programmatically. For some reason, when I try to add controls to my form (in design view), it comes back and tells me that the control cannot be added (but gives no reason). The code that is doing this is (in the parent form's Load event):
Dim ctl As TextBox
Dim s() As String
Dim newName As String
...
DoCmd.OpenForm "sfrmEquipmentDatasheet", acDesign
For Each f In fieldColls(0) 'fieldColls is an array of Collections
s = Split(f.desc, ":") 'f is a class with a property 'desc'
If Left(s(0), 1) = "_" Then
newName = s(2)
ElseIf Len(s(0)) = 0 Then
newName = s(4)
Else
newName = s(0)
End If
If Not hasElement(Form_sfrmEquipmentDatasheet.Controls, newName) Then
Set ctl = CreateControl("sfrmEquipmentDatasheet", acTextBox) '!!!This is where the error occurs!!!
ctl.ControlSource = f.name
ctl.name = newName
ctl.ColumnHidden = True
End If
Next f
The second questions has to do with the fields in a TableDef. My original plan was to create collections of fields by using the existing field objects in the fields of table definitions. But when I tried this:
dim fld as Field
set fld = CurrentDB.TableDefs("myTable").Fields("myField")
...it came back with a Type Mismatch error. When I made fld more generic, it responded that an object no longer existed (referring, I believe, to the fields collection).
Any suggestions?
Thanks!
-- Jeff