VBA requirements

I have done a simple payroll for a small company and it working fine. Now in the sub report where we capture deductions , such as loans & advances I just want all the  deduction to be captured in one line and at the end of the line access should not allow the courser to go to the second line.

How can I archive that by using VBA??????????

I do not want to start summing data again because it will changing a lot of objects, any help on this will be highly appreciated.


Hankwembo Christopher,FCCA,FZICA,CIA,MAAT,B.A.ScDirectorAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

John TsioumprisSoftware & Systems EngineerCommented:
Without knowing the exact structure of your report/subreport a possible solution would be to add a group on your subreport and on the footer
 of the group perform the sum of the deductions
Hankwembo Christopher,FCCA,FZICA,CIA,MAAT,B.A.ScDirectorAuthor Commented:
Sorry may be I was not clear here, what I'm saying is that I have a subform attached to the parent form, now in the subform instead of having endless number of lines or rows created I want to limit the rows to one. Here is the code I'm trying but I seam not to get it right , may be Im making a mistake some where, please check:

Private Sub Form_BeforeInsert(Cancel as Integer)
If DCount("*", "[childtable]", "[ID] = " & Me!ID) >= 1 Then
MsgBox "Only one records allowed", vbOKOnly
Cancel = True
End If
End Sub

Please note Child table represent table name attached to the subform


Dale FyeOwner, Dev-Soln LLCCommented:
Personally, I prefer to use the AllowAdditions method of the form.  So that in the main forms current event, I would check to see whether there is already 1 or more records in the subform, and if so, set the subforms AllowAdditions properly to false.
If DCount("*", "[childtable]", "[ID] = " & Me!ID) >= 1 Then me.subformcontrolname.form.AllowAdditions = false

Open in new window

Then, in the subforms AfterUpdate event, I would perform a similar check.  This would allow the 1st record to be created and edited, but after that record is written to the table, then the Form_Afterupdate event would set the AllowAdditions properly to false.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.