paulc
March 19th, 2001, 03:54 AM
Hi all,
Curently, I am trying to use a subroutine in a module to create a control array, passing in the 0th member of the array as the parameter.
Here is the code in part which does this:
Sub CreateArray(ByRef frm As Form, ltblname As Control, lfldname() As Control, tflddata() As Control)
On Error GoTo CreateArrayError:
Dim varField As Variant
i = 0
' Setup dynamic array for controls that display data
For Each varField In gQuerySet.Fields
If i = 0 Then
' sets 0th label caption
lfldname(i).Caption = varField.name & ":"
nFieldType = varField.Type
' set size of 0th textbox
tflddata(i).width = GetFieldWidth(nFieldType)
If nFieldType = dbText Then
tflddata(i).MaxLength = varField.Size
tflddata(i).TabIndex = 0
End If
' bind textbox to datacontrol
tflddata(i).DataField = varField.name
i = i + 1
Else
' load ith label
Load lfldname(i)
lfldname(i).top = (i * gnCTLARRAYHEIGHT) + tflddata(0).top
lfldname(i).Visible = True
' load ith textbox
Load tflddata(i)
tflddata(i).top = lfldname(i).top
tflddata(i).Visible = True
' set ith label caption
lfldname(i).Caption = varField.name & ":"
nFieldType = varField.Type
' set textbox width
tflddata(i).width = GetFieldWidth(nFieldType)
If nFieldType = dbText Then
tflddata(i).MaxLength = varField.Size
tflddata(i).TabIndex = i
End If
' bind ith textbox to data control
tflddata(i).DataField = varField.name
i = i + 1
End If
Next
intFields = i
Exit Sub
CreateArrayError:
MsgBox Error(Err), vbOKOnly, "CreateArray"
Resume
End Sub
I am using the following code to call this function:
CreateArray frmEditor, lblTableName, lblfieldname, txtFieldData
but it don't work.
I have tried passing in the lblfieldname and txtfielddata controls as lblfieldname(i) and txtfielddata(i) and also setting the passed in control to lfldname(i) and tflddata().
Any ideas if this is even possible, or do I have to create the array first and then pass in the whole array to a function which can then so the sizing and placement etc.???
cheers
Paul
Curently, I am trying to use a subroutine in a module to create a control array, passing in the 0th member of the array as the parameter.
Here is the code in part which does this:
Sub CreateArray(ByRef frm As Form, ltblname As Control, lfldname() As Control, tflddata() As Control)
On Error GoTo CreateArrayError:
Dim varField As Variant
i = 0
' Setup dynamic array for controls that display data
For Each varField In gQuerySet.Fields
If i = 0 Then
' sets 0th label caption
lfldname(i).Caption = varField.name & ":"
nFieldType = varField.Type
' set size of 0th textbox
tflddata(i).width = GetFieldWidth(nFieldType)
If nFieldType = dbText Then
tflddata(i).MaxLength = varField.Size
tflddata(i).TabIndex = 0
End If
' bind textbox to datacontrol
tflddata(i).DataField = varField.name
i = i + 1
Else
' load ith label
Load lfldname(i)
lfldname(i).top = (i * gnCTLARRAYHEIGHT) + tflddata(0).top
lfldname(i).Visible = True
' load ith textbox
Load tflddata(i)
tflddata(i).top = lfldname(i).top
tflddata(i).Visible = True
' set ith label caption
lfldname(i).Caption = varField.name & ":"
nFieldType = varField.Type
' set textbox width
tflddata(i).width = GetFieldWidth(nFieldType)
If nFieldType = dbText Then
tflddata(i).MaxLength = varField.Size
tflddata(i).TabIndex = i
End If
' bind ith textbox to data control
tflddata(i).DataField = varField.name
i = i + 1
End If
Next
intFields = i
Exit Sub
CreateArrayError:
MsgBox Error(Err), vbOKOnly, "CreateArray"
Resume
End Sub
I am using the following code to call this function:
CreateArray frmEditor, lblTableName, lblfieldname, txtFieldData
but it don't work.
I have tried passing in the lblfieldname and txtfielddata controls as lblfieldname(i) and txtfielddata(i) and also setting the passed in control to lfldname(i) and tflddata().
Any ideas if this is even possible, or do I have to create the array first and then pass in the whole array to a function which can then so the sizing and placement etc.???
cheers
Paul