View Full Version : Code Repeated .... Can I use a function and call it ?


jagstirling
09-16-2008, 10:04 PM
I would be be gratefuil if someone could look at the attached database.

Firstly, the databse is not my own work but it has been adapted slightly from a sample on the internet.

Secondly, I have two After Update events running on frmCalendar relating to combo boxes cboMonth and cboEmployeeID.

They both run the same code.

Can I not have the code stored once (as a function) and call it from each After Update event. That way I only need maintain the one source of code.

I have tried but my cannot seem to get it to work. Can some one have an attempt and repost so I can see where I was going wrong.

Thanks in advance.

DCrake
09-17-2008, 12:06 AM
What you need to do is to create a function as such

Public Function UpdateCalander()

If Me.cboMonth = "" Or Me.cboEmployeeID = "" Then
Exit Function
Endif

..enter code here


End Function

Then on the AfterUpdate on both controls enter

Call UpdateCalander()

This will check that there is a value in both the month and the employee before it refreshes the form.

CodeMaster::cool: