Ok i am pulling my hair out here i am desperate for some help.
I am writing a database at the moment (hence my post), i am struggling with something that is doing my nut so i will try to explain the basics here:
I have a main form and a subform, the main form consists of a list of different medicines via a combo box and some other related fields to that medicine. Then in the main form i have a subform which consists of i list of medicine administration dates and other related fields.
1 of the fields in the subform is an 'amount' field where i enter the amount of medicine that is administered on an animal. In the footer i have a text field that sums the total with =sum([Amount])
that works OK.....
Back in the main form i have a field that shows how much medicine was purchased (control source is AmountPurchased from table), then under that is a text box thats control source is the 'sum' from the subform.....that works OK too.
Under that is another text box which is qtyLeft. This also works OK and displays the calculated amount of medicine that is left. Now...going back to the subform, when i entered or changed the quantity in the amount field it initially would not update the qtyLeft until i finished entering the rest of the record. So what i had to do was, in the event onExit, add DoCmd.RunCommand acCmdSaveRecord which worked fine. When i exited the amount field it would save the record and update the calculated fields up in the main form.
Now here is where my problem starts....
In the main form i have got another field under the qtyLeft which is AmountLeft, and also a tick box next to it that is called "Empty". This AmountLeft field is not calculated but SHOULD get its value from the qtyLeft calculated field IF the Empty tick box is not ticked.
Now i'm trying not to confuse the reader, and the reader might ask why this is so, so i feel i should explain why. OK....lets say the medicine is a bottle of say 100ml of medicine, the subform is a list of dates that the medicine was used. At some point there may only be 5ml or so left or the expiry date of the medicine maybe past so i have set an OnClick event for the Empty tick box which when clicked sets the AmountLeft to Zero (for the reports). This works fine too.....even though the qtyLeft field still shows 5ml this is fine because it is just a calculated text box that saves no where. The AmountLeft is what writes back to the main table via the query.
Hope ya with me so far.
In the main form i have an OnCurrent event that reads something like this:
If Me.Empty = True Then
Me.AmountLeft = 0
End If
So when i scroll through the main form medicine it knows to keep the AmountLeft field as Zero if the Empty tick box is ticked.
BUT when i change it to:
If Me.Empty = True Then
Me.AmountLeft = 0
Else
Me.AmountLeft = Me.qtyLeft
End If
IT DOESN'T WORK............this is my problem. The AmountLeft field ALWAYS shows the original AmountPurchased.
I have tried adding an OnExit event to the Amount field in the subform like this:
DoCmd.RunCommand acCmdSaveRecord (this forces an update of the qtyLeft calculated textbox)
If forms!frmMedicineAdministered!Empty = False Then
Forms!frmMedicineAdministered!AmountLeft = forms!frmMedicineAdministered!qtyLeft
End If
But this only seems to work if i exit the Amount field in the subform THEN go back in and back out of it.
I have also tried doing it via a macro with the same problem, i have also tried many other things but whilst the qtyLeft field updates OK i just can't get it to update the AmountLeft field to match if the Empty tick box is not ticked.
Sorry if this problem took so long to explain but it is seriously annoying me now and maybe the solution is staring me in the face.
I can upload my db or some screen shots if this would be helpful.
Many thanks in advance for any help - i have learnt so much from this forum already and really do appreciate everyones help.
I am writing a database at the moment (hence my post), i am struggling with something that is doing my nut so i will try to explain the basics here:
I have a main form and a subform, the main form consists of a list of different medicines via a combo box and some other related fields to that medicine. Then in the main form i have a subform which consists of i list of medicine administration dates and other related fields.
1 of the fields in the subform is an 'amount' field where i enter the amount of medicine that is administered on an animal. In the footer i have a text field that sums the total with =sum([Amount])
that works OK.....
Back in the main form i have a field that shows how much medicine was purchased (control source is AmountPurchased from table), then under that is a text box thats control source is the 'sum' from the subform.....that works OK too.
Under that is another text box which is qtyLeft. This also works OK and displays the calculated amount of medicine that is left. Now...going back to the subform, when i entered or changed the quantity in the amount field it initially would not update the qtyLeft until i finished entering the rest of the record. So what i had to do was, in the event onExit, add DoCmd.RunCommand acCmdSaveRecord which worked fine. When i exited the amount field it would save the record and update the calculated fields up in the main form.
Now here is where my problem starts....
In the main form i have got another field under the qtyLeft which is AmountLeft, and also a tick box next to it that is called "Empty". This AmountLeft field is not calculated but SHOULD get its value from the qtyLeft calculated field IF the Empty tick box is not ticked.
Now i'm trying not to confuse the reader, and the reader might ask why this is so, so i feel i should explain why. OK....lets say the medicine is a bottle of say 100ml of medicine, the subform is a list of dates that the medicine was used. At some point there may only be 5ml or so left or the expiry date of the medicine maybe past so i have set an OnClick event for the Empty tick box which when clicked sets the AmountLeft to Zero (for the reports). This works fine too.....even though the qtyLeft field still shows 5ml this is fine because it is just a calculated text box that saves no where. The AmountLeft is what writes back to the main table via the query.
Hope ya with me so far.
In the main form i have an OnCurrent event that reads something like this:
If Me.Empty = True Then
Me.AmountLeft = 0
End If
So when i scroll through the main form medicine it knows to keep the AmountLeft field as Zero if the Empty tick box is ticked.
BUT when i change it to:
If Me.Empty = True Then
Me.AmountLeft = 0
Else
Me.AmountLeft = Me.qtyLeft
End If
IT DOESN'T WORK............this is my problem. The AmountLeft field ALWAYS shows the original AmountPurchased.
I have tried adding an OnExit event to the Amount field in the subform like this:
DoCmd.RunCommand acCmdSaveRecord (this forces an update of the qtyLeft calculated textbox)
If forms!frmMedicineAdministered!Empty = False Then
Forms!frmMedicineAdministered!AmountLeft = forms!frmMedicineAdministered!qtyLeft
End If
But this only seems to work if i exit the Amount field in the subform THEN go back in and back out of it.
I have also tried doing it via a macro with the same problem, i have also tried many other things but whilst the qtyLeft field updates OK i just can't get it to update the AmountLeft field to match if the Empty tick box is not ticked.
Sorry if this problem took so long to explain but it is seriously annoying me now and maybe the solution is staring me in the face.
I can upload my db or some screen shots if this would be helpful.
Many thanks in advance for any help - i have learnt so much from this forum already and really do appreciate everyones help.