Avatar of ouestque
ouestque
Flag for United States of America asked on

Access: Help with code: Using CreateEventProc

I have attached a snippet of code. When I run it I get the following error:

"Run-Time Error '57017': Event Handler is invalid"

Will someone help me make the attached code work?


DoCmd.OpenForm "SampleForm", acDesign
 
a = 0
b=0 
Do
    
    Set cmd = CreateControl(b, acCommandButton)
        
    cmd.Name = "Custom " & a
    cmd.Caption = "Customize " & a
    cmd.OnClick = "[Event Procedure]"
    
InsertCode = Forms![SampleForm].Module.CreateEventProc("Click", cmd.Name)
 
b=b+1
a = a + 1
rst.MoveNext
count = count - 1
Loop While (count > 0)
 
DoCmd.Close acForm, "SampleForm", acSaveYes

Open in new window

Microsoft Access

Avatar of undefined
Last Comment
stevbe

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
stevbe

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
stevbe

Another issue is that you can not have a space in the control name when you use the CreateEventProperty

change ...

cmd.Name = "Custom " & a
   to
cmd.Name = "Custom" & a


Steve
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck