By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,308 Members | 1,929 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,308 IT Pros & Developers. It's quick & easy.

Generating event-code in MS-access

P: n/a
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
Nov 12 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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" <to******@netscape.net> wrote in message
news:13**************************@posting.google.c om...
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

Nov 12 '05 #2

P: 4
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]
Feb 24 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.