problem with subform synchronising

C

Carnafex

Im currently writing a personel database and have gotten some problem
with the code that I cant seem to fix. The problem is that I have a
subform (inside a tab if that makes any difference) that is meant to be
synchronised with the record of the main form.
The Subform contains multiple records that relate to a persons sick
days, so when the main form is displaying one person, this subform is
displaying his sicks days.
I do some calculations in the subform that do a date check to check how
many sick days the person had in the last month, 3 months and last year
(using a datediff function). I then place a summary of this information
on the first page of the tab (subform is on page 3) using a simple
control source.
The problem is this, that when the main form record is changed to a
different person, the code that adds the sick days together and
displays it doesnt remain in sync with the main form. By this I mean
just say bob's record is the current one on the main form, and if I
switch to joe, the subform doesnt run the calculations again, so that
the summary is still displaying bob's info.
The code I use in the subform is listed below (running in the
form_current proceedure)

**********CODE**************
'Ill mark important variables, and ignore the rest

dim AF as boolean, FC and boolean
dim number as Integer, total as integer
dim recsetSA as recordset
'some other dims

On error goto Err_Code:

If AF = False then
recsetSA = Me.Form.RecordsetClone
end if

recsetSA.movelast
recsetSA.movefirst
total = recsetSA.recordcount 'populate recsetSA

If (number > total)
AF = False
FC = false
'set other variables to 0
'resets the calculated textboxes
number = 0
end if

Do until (me.currentrecord >= total)
IF ...
'lots of code for adding up sick days
end if
number = number + 1
DoCmd.GoToRecord, , acNext, 1
loop
exit sub

error_code:
If FC = False
'add sick days up
FC = true
end if

'Display total sick days to text boxes
'in subform here
Resume next
End sub

***********END CODE***********

Any help to get this in sync would be greatly appreciated.
Thanks,
Jason
 
L

Larry Linson

Perhaps you need to run the code in the Current event of the _main_ form,
not the Form embedded in the Subform Control?

Larry Linson
Microsoft Access MVP
 

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