我在重置按钮上有以下代码:
Private Sub cmdReset_Click()
Dim ctl As Control
For Each ctl In Me.Controls
Select Case ctl.ControlType
Case acComboBox
ctl.Value = ctl.DefaultValue
End Select
Next
Me.Requery
End Sub
这是组合框的默认值:
=DLookUp("FieldName","TableName","strCriteria")
当我单击“重置”按钮时,组合框只会将等式显示为字符串=DLookUp("FieldName","TableName","strCriteria")
,而不是实际运行该功能。我尝试使用其他默认值=[cboName].[ItemData](#)
并且它是同一个问题。表格完美无缺。
感谢您的帮助。
答案 0 :(得分:0)
行为是预期的,因为Windows("report.xls").Activate 'This activate the report
Range("B2").Select 'This selects B2 cell
Range(Selection, Selection.End(xlDown)).Select 'This expands the selection down
Selection.Copy 'This copy the selection.
Windows("AT.xlsm").Activate 'This activate the AT file
Range("B2").Select '**** Here you should modify to select the Paste destination cell
ActiveSheet.Paste 'This Paste the values
返回字符串默认值属性,而不是实际计算的默认值。
一种可能的方法是使用ctl.DefaultValue
来计算实际的默认值。但请注意,执行此操作时可能会出现许多问题,因为默认值不是VBA,而是Access表达式,因此它具有不同的范围,并且对区域设置(如列表分隔符设置)很敏感。
您可以使用以下行:
Eval