我有三种产品,玉米、豆类和萝卜。我每个都有不同的规格,有些相同......水分,颜色,蛋白质,脂肪......我有一些未绑定的文本框和一些连续形式的标签。还有两个按钮可以让我按在两个文本框中输入的日期进行排序或全部显示。我在表单标题中有标签和文本框,在详细信息部分有文本框。表单标题部分中的文本框正在获取它们排列的每个字段的平均值。
当我打开表单并选择 Beans 时,一切都完美地显示出来了!我可以排序或显示所有,这很好。我可以切换到 Corn 并执行相同操作,但是当我尝试切换回 Beans 时,Average 文本框会显示 #Error。如果我打开表单并先转到 Corn,然后是 Beans 并返回 Corn,Corn 两次都可以,但 beans 不起作用。Beans 仅当它是表单上打开的第一个东西时才会起作用,并且会继续工作,直到您选择另一个产品。无论如何,玉米和萝卜都可以,但是当我切换回 Beans 时,我再次收到 #Error。
两个代码块之间几乎没有区别。还有什么可能导致平均文本框(Text12-Text15)中的#Error?
这是代码的一部分....此代码位于其各自按钮的 OnClick 事件中
对于玉米
Me.Label2.Caption = "Moisture"
Me.Label3.Caption = "Starch"
Me.Label4.Caption = "Protein"
Me.Label5.Caption = "Fat"
Me.Text2.ControlSource = " Moisture "
Me.Text3.ControlSource = " Starch "
Me.Text4.ControlSource = " Protein "
Me.Text5.ControlSource = " Fat "
Me.Text12.ControlSource = "=Avg([Moisture])"
Me.Text13.ControlSource = "=Avg([Starch])"
Me.Text14.ControlSource = "=Avg([Protein])"
Me.Text15.ControlSource = "=Avg([Fat])"
Me.RecordSource = "SELECT SampleID.DateCreated, SampleID.SampleLocationID, PertenData.Moisture, PertenData.Starch, PertenData.Protein, PertenData.Fat FROM SampleID INNER JOIN PertenData ON SampleID.SampleID = PertenData.PertenSampleID WHERE ((SampleID.SampleLocationID)=21) ORDER BY SampleID.DateCreated DESC"
豆类
Me.Label2.Caption = "Moisture"
Me.Label3.Caption = "Starch"
Me.Label4.Caption = "Protein"
Me.Label5.Caption = "Color"
Me.Text2.ControlSource = " Moisture "
Me.Text3.ControlSource = " Starch "
Me.Text4.ControlSource = " Protein "
Me.Text5.ControlSource = " Color"
Me.Text12.ControlSource = "=Avg([Moisture])"
Me.Text13.ControlSource = "=Avg([Starch])"
Me.Text14.ControlSource = "=Avg([Protein])"
Me.Text15.ControlSource = "=Avg([Color])"
Me.RecordSource = "SELECT SampleID.DateCreated, SampleID.SampleLocationID, PertenData.Moisture, PertenData.Starch, PertenData.Protein, PertenData.Color FROM SampleID INNER JOIN PertenData ON SampleID.SampleID = PertenData.PertenSampleID WHERE ((SampleID.SampleLocationID)=35) ORDER BY SampleID.DateCreated DESC"