I have three products, Corn and Beans and radishes. I have different specifications on each, and some the same… moisture, color, protein, fat…. I have some unbound textboxes and some labels in a continuous form. There are also two buttons that allow me sort by dates entered in two textboxes or show all. I have labels and textboxes in the formheader and textboxes in the detail section. The textboxes in the form header section are getting averages of each field they line up with.
When I open form and select Beans, everything shows up perfectly! I can sort or show all and it is fine. I can switch to Corn and do the same, but when I try to switch back to Beans, the Average textboxes display #Error. If I open the form and go to Corn first, then Beans and back to Corn, Corn works both times, but beans does not work. Beans will only work if it is the first thing opened on the form, and will continue to work until you select another product. Corn and radishes will work no matter what, but when I switch back to Beans, I get the #Error again.
There is virtually no difference between the two code blocks. What else could be causing the #Error in the Avg textboxes (Text12-Text15)?
Here is part of the code…. this code is in the OnClick Event for their respective buttons
For CORN
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"
For BEANS
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"
The problem was directly related to bound textboxes. My different samples had differing numbers of data categories that needed to be shown, but by setting the visible property of a textbox to false was still causing problems in the visible textboxes. To set a textbox back to ‘unbound’ I used
After changing the textboxes back to an unbound state and then rebind them to your new control source. This has permanently stopped the problem. I have now 5 products and any combination of those 5 works flawlessly. Thanks to all for your help.