好吧,这是另一个线程的后续内容。
我有一个Person
桌子,上面有几个字段
该表以三种不同的方式呈现给用户:
3)作为报告(没有图片,但类似于数据表)
特殊标签§Person§
已添加到表单中,以选择附加表的主表
还有一个查询,返回给定field
中每个table
的错误及其格式规则
这是一段代码,用于在加载每个表单,报表,数据表时为它们定义条件格式规则。
Private Sub Form_Open(Cancel As Integer)
Call validazione.validate(Form)
End Sub
Function validate(aForm As Form)
Call DeleteFormats(aForm) ' to remove existing formats
Call setFormats(aForm) ' to insert the new formats
End Function
setFormat子项如下:
Sub setFormats(aForm As Form)
Dim TableName As String, t() As String, ErrSQL As String, ctlName As String
Dim ErrRst As DAO.Recordset, FormCtl As Control, ctl As Variant
Dim frmtCount As Integer, Cnt As Integer
Dim fcdSource As FormatCondition, fcdDestination As FormatCondition
Dim varOperator As Variant, varType As Variant, x As Variant, y As Variant
Dim varExpression1 As Variant, varExpression2 As Variant
Dim intConditionCount As Integer, intCount As Integer
If Len(aForm.Tag) > 0 And Mid$(aForm.Tag, 1, 1) = "§" Then
t = Split(aForm.Tag, "§", 1)
If Len(t(0)) > 0 Then TableName = t(0)
TableName = Replace(TableName, "§", "")
ErrSQL = "SELECT * FROM [Q Errori per tabella] WHERE ([TableName] = """ & TableName & """);"
Set ErrRst = CurrentDb.OpenRecordset(ErrSQL, , dbReadOnly)
If ErrRst.EOF Then Exit Sub
' ***IT RUNS UNTIL HERE***
FormCtl = aForm.Controls("CAP")
y = aForm.Properties(ctlName).Item("Codice Fiscale")
With ErrRst
.MoveFirst
Do Until .EOF
x = ErrRst.Fields("FieldName")
Debug.Print x
' On Error GoTo fine
FormCtl = aForm.Controls("CAP")
FormCtl = aForm.
On Error GoTo 0
If FormCtl.ControlType = acTextBox Or FormCtl.ControlType = acComboBox Then
' Add the FormatCondition
Cnt = FormCtl.FormatConditions + 1
FormCtl.FormatConditions.Add acExpression, , .Fields.Item(Cnt).Value
' Reference the FormatCondition to apply formatting.
' Note: The FormatCondition cannot be referenced
' in this manner until it exists.
Set fcdDestination = ctl.FormatConditions.Item(Cnt).Value
With FormCtl.FormatConditions.Item(Cnt)
.BackColor = Eval("RGB" & ErrRst.item("Sfondo").value)
' .FontBold = fcdSource.FontBold
' .FontItalic = fcdSource.FontItalic
' .FontUnderline = fcdSource.FontUnderline
.ForeColor = Eval("RGB" & ErrRst.item("pen").value)
End With
End If
fine: On Error GoTo 0
' Next x
.MoveNext
Loop
End With
End If
End Sub
***好吧,它看起来很疯狂,但是我的问题是如何访问表单字段,报表列或数据表列by name
。
此外,我想只使用一种功能来管理所有三个选项:表格,报表和数据表。
有人可以帮忙吗? TIA 保罗