Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Checkbox from subform to trigger change in textbox on main form

Status
Not open for further replies.

metrodub

Technical User
Dec 29, 2004
82
US
Hello,

I have a main form (frmClass) that contains a subform (sfrmMaterials).

The materials subform populates when a user chooses a course from a course combobox. The fields that populate in the subform are Instrument, Cost, Vendor and a checkbox (chkSelected).

What I would like to do is have the user be able to check the checkbox next to the instruments they would like to use and have the sum of the total cost of instruments checked multiplied by the estimated number of students (txtEstStudents on the main form) display in a textbox on the main form.

To note, the checkbox in the continuous subform is bound to a field (Selected) in the materials table.

I was able to get this to work with one minor issue. The event doesn't happen until the user selects a second checkbox. For example, if a user selects a course (say there is only 1 student) and it contains 2 instruments (a book ($10) and pad of paper($1)), and the user selects the book, the txtbox with the total cost for materials will not change until the user checks the pad of paper. At this point, the total will be $10 and the pad of paper will not be added.

Here is the code that I used -
Code:
Private Sub chkSelected_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    
Forms!frmClass!txtMaterialsFee = DSum("Cost", "qryMaterials", "CourseID = " & [Forms]![frmClass]![cboCourseList] & " AND " & "Selected = -1") * Forms!frmClass!txtEstStudents

End Sub

I have tried this code on the AfterUpdate and Click events as well with the same result.

Any help getting the event to work on the first check would be appreciated.

Thanks.
 
you may try this:
Private Sub chkSelected_AfterUpdate()
Me.Dirty = False
Forms!frmClass!txtMaterialsFee = DSum("Cost", "qryMaterials", "CourseID=" & Forms!frmClass!cboCourseList & " AND Selected=True") * Forms!frmClass!txtEstStudents
End Sub

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top