Selecting Multiple records in subform to update table button code

  • Thread starter serviceman via AccessMonster.com
  • Start date
S

serviceman via AccessMonster.com

The more I learn, the more I trouble I get into...
I have a table ATTENDANCE_HDR that has a one to many ralationship with table
TESTRESULTS. PK on ATTENDANCE_HDR is event_dat,event_id,location_id and on
TESTRESULTS it is event_dat,event_id,location_id, and student_id. I have
created a form for ATTENDANCE_HDR that has a combobox lookup on event_id.
Adding a subform based on TESTRESULTS is ok, and we need to look up
student_id from table STUDENTS in order to add a record. A combobox works
fine for single record entry, but for this form I would like to do multiple
record entries at once. I have played with list boxes, but I really like the
looks of a non-related datasheet subform on table STUDENTS joined with a temp
table and a yes/no check box. I can get this all added fine, but I just
CANNOT get the code for a button to take the selected students and related
data from the main form key fields and insert/update TESTRESULTS., then clear
the checkboxes in the temp table for the next session.
HELP!! I can't figure this out and my coffee pot is getting empty!
Andy
 
S

serviceman via AccessMonster.com

Ok,
An update. I've created a form called studententrylist bound to table
students. This form is loosely based on Kallal's multi select form. So now my
main form for ATTENDANCE_HDR has a subform TESTRESULTS linked to it and this
subform has studententrylist embedded into it. Studententrylist is *NOT*
linked by STUDENT_ID, so is unbound. Each row in this form has a checkbox,
check11, which is wrapped by command13. The code for these is:

Private Sub Check11_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeySpace Then
KeyCode = 0
Call Command13_Click
End If
End Sub

Private Sub Command13_Click()
'Debug.Print "contact = " & Me.ContactID
If IsChecked(Me.STUDENT_ID) = False Then
colCheckBox.Add CLng(Me.STUDENT_ID), CStr(Me.STUDENT_ID)
Else
colCheckBox.Remove (CStr(Me.STUDENT_ID))
End If
Me.Check11.requery
End Sub

At this point it is all working fine. All I need now is the update code for a
command button to add the selected records. I need to loop through all of the
students, and for each one where Check11 is true insert a record into
TESTRESULTS using student_id and EVENT_ID,EVENT_DAT, and LOCATION_ID from the
main form.
I've looked at several pieces of code here, but just cannot get one working.
Andy
 
S

serviceman via AccessMonster.com

Never mind,
I got it:
I put the INSERT code into an SQL string in the onclick event...
Andy
Ok,
An update. I've created a form called studententrylist bound to table
students. This form is loosely based on Kallal's multi select form. So now my
main form for ATTENDANCE_HDR has a subform TESTRESULTS linked to it and this
subform has studententrylist embedded into it. Studententrylist is *NOT*
linked by STUDENT_ID, so is unbound. Each row in this form has a checkbox,
check11, which is wrapped by command13. The code for these is:

Private Sub Check11_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeySpace Then
KeyCode = 0
Call Command13_Click
End If
End Sub

Private Sub Command13_Click()
'Debug.Print "contact = " & Me.ContactID
If IsChecked(Me.STUDENT_ID) = False Then
colCheckBox.Add CLng(Me.STUDENT_ID), CStr(Me.STUDENT_ID)
Else
colCheckBox.Remove (CStr(Me.STUDENT_ID))
End If
Me.Check11.requery
End Sub

At this point it is all working fine. All I need now is the update code for a
command button to add the selected records. I need to loop through all of the
students, and for each one where Check11 is true insert a record into
TESTRESULTS using student_id and EVENT_ID,EVENT_DAT, and LOCATION_ID from the
main form.
I've looked at several pieces of code here, but just cannot get one working.
Andy
The more I learn, the more I trouble I get into...
I have a table ATTENDANCE_HDR that has a one to many ralationship with table
[quoted text clipped - 12 lines]
HELP!! I can't figure this out and my coffee pot is getting empty!
Andy
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top