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

ACCESS 2000: Problem Calling Sub using the eval method

P: n/a
I have a form with 100 images (named from img1 to img100) and a Click
event associated to each one.
I want to write a function that calls these events.

I have tried the following:

Dim imgEvent as Variant
For i = 1 to 100
imgEvent = "img" & Format$(i) & "_Click" 'Create image name.
Call Eval(imgEvent)
'Call Eval(Me(eval(imgEvent))) 'Didn't work either
'Call Eval(Me!eval(imgEvent)) 'Didn't work either
Next i

The only thing I get is an 2482 error (Could not find the name
'img1_Click').

I AM DESPARATE!!!!!!!!!!!!!!!!!!!!!!!
I have looked everywhere and couldn't find a thing!
P L E A S E H E L P M E ! ! ! ! !
Nov 13 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Kostis,
To what end? Why loop through the image frames? If you made a one-time
pass through the frames and set an action to the click event of each, would
you not accomplish the same thing? Ok, mebbe it ain't as pretty, but it
would get the job done.

"Kostis" <ne*********@hotmail.com> wrote in message
news:65**************************@posting.google.c om...
I have a form with 100 images (named from img1 to img100) and a Click
event associated to each one.
I want to write a function that calls these events.

I have tried the following:

Dim imgEvent as Variant
For i = 1 to 100
imgEvent = "img" & Format$(i) & "_Click" 'Create image name.
Call Eval(imgEvent)
'Call Eval(Me(eval(imgEvent))) 'Didn't work either
'Call Eval(Me!eval(imgEvent)) 'Didn't work either
Next i

The only thing I get is an 2482 error (Could not find the name
'img1_Click').

I AM DESPARATE!!!!!!!!!!!!!!!!!!!!!!!
I have looked everywhere and couldn't find a thing!
P L E A S E H E L P M E ! ! ! ! !

Nov 13 '05 #2

P: n/a
Not sure if you can do what you ask, but you can programmatically assign a
function name to the OnClick property of each control.

This example assumes you want to call a function called MyProc1() for img1,
MyProc2() for img2, etc.

Dim ctl As Control
Dim strForm As String
Dim strFuncName As String

strForm = "NameOfYourFormHere"
DoCmd.OpenForm strForm, acDesign, WindowMode:=acHidden
With Forms(strForm)
For Each ctl in .Controls
If ctl.ControlType = acImage Then
strFuncName = "=MyProc" & Mid(ctl.Name, 4) & "()"
ctl.OnClick = strFuncName
End If
Next
End With

Set ctl = Nothing
DoCmd.Close acForm, strForm, acSaveYes

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Kostis" <ne*********@hotmail.com> wrote in message
news:65**************************@posting.google.c om...
I have a form with 100 images (named from img1 to img100) and a Click
event associated to each one.
I want to write a function that calls these events.

I have tried the following:

Dim imgEvent as Variant
For i = 1 to 100
imgEvent = "img" & Format$(i) & "_Click" 'Create image name.
Call Eval(imgEvent)
'Call Eval(Me(eval(imgEvent))) 'Didn't work either
'Call Eval(Me!eval(imgEvent)) 'Didn't work either
Next i

The only thing I get is an 2482 error (Could not find the name
'img1_Click').

I AM DESPARATE!!!!!!!!!!!!!!!!!!!!!!!
I have looked everywhere and couldn't find a thing!
P L E A S E H E L P M E ! ! ! ! !

Nov 13 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.