Populating a field for each record in a subform

Badswell

Registered User.
Local time
Today, 07:16
Joined
Feb 13, 2004
Messages
34
I have a form with a subform on it. When the user clicks a button, I need it to populate a field on the subform for each record in the subform. I am using a foreign key for the subform which is equal to the primary key on the form. I can get it to work on the first record in the subform using a DO WHILE or IF statement, but it will not advance to the next record. The code I've been fighting with it pasted below. Does anyone have any suggestions?

Do While Forms![Overview]![Subform2]!ID = Forms![Overview]![Subform2]!ID
If Forms![Overview]![Subform2]![SPIN Code].Value <> "COSCU" Then
Forms![Overview]![Subform2]![Signoff].Value = uname
Forms![Overview]![Subform2]![Signoff Date].Value = Date + 1
End If
DoCmd.FindNext
Loop
 
Use a recordsetclone of your subform and cycle through each record via ADP or DAO.

DAO (starter) code for a subroloutine or function follows:

dim rs as dao.recordset
set rs = forms!YourMainformName!YourSubformName.recordsetclone
rs.movefirst
'check for no records
if rs.eof and rs.bof then exit sub/function (as appropriate)
do until rs. eof
If rs!SPIN Code <> "COSCU" Then
rs!Signoff= (build a reference to)uname
rs![Signoff Date]= Date + 1 'blank in field names cause trouble
End If
rs.movemext
loop
rs.close
set rs=nothing

Be sure that you have DAO 6.0 Reference set.
 

Users who are viewing this thread

Back
Top Bottom