I don't think that the answer of Larry was very helpfull.
Hopefully mine is better... :rolleyes:
Dim frm As Form, mdl As Module
Dim strName As String
Set frm = CreateForm
strName = frm.Name
Return reference to form module.
Set mdl = frm.Module
' Add event procedure for the Form Close Event
mdl.InsertLines mdl.CountOfLines + 1, "Private Sub Form_Close()"
mdl.InsertLines mdl.CountOfLines + 1, vbTab & "'Here your code"
mdl.InsertLines mdl.CountOfLines + 1, "end sub"
frm.OnClose = "[Event Procedure]"
DoCmd.Save acForm, frm.Name
DoCmd.Close acForm, frm.Name
DoCmd.Rename "MyFormName", acForm, strName
Is there some compelling reason why you'd want to create the Report and the
code via code, rather than doing it in design view? You can create both that
you modify with code at runtime if necessary, but the kind of thing you
illustrate is normally only used in Wizards and such to run at design time.
Larry Linson
Microsoft Access MVP
"Tom Seichter" <tomancer@netscape.net> wrote in message
news:13742567.0403071344.614cc13b@posting.google.c om...[color=blue]
> Hi there,
>
> I want to generate reports with a fixed behavior for the Close event.
> Therefor I'm programming a function like
>
> Function CreateEvent() ...
> Dim rpt as Report, mdl as Module, lngReturn as Long
> Set rpt = CreateReport
> rpt.HasModule = True
> Set mdl = rpt.Module
> lngReturn = mdl.CreateEventProc("OnClose", rpt.Name)
> ...
>
> My problem is an error-message: '57017, Event-Routine not valid' I
> always get when I'm executing the CreateEventProc() function. I
> changed the first argument to 'Close', 'Close()', 'OnClose()'... but
> the error-message is the same.
> Does someone can help me, what is the correct value of this argument,
> or give me a hint what error I'm doing.
>
> Thanks Tom[/color]