Call a button's action from VBA (1 Viewer)

Dave E

Registered User.
Local time
Today, 06:38
Joined
Sep 23, 2019
Messages
139
Hi All,

Interesting problem today.
I have a continuous form which shows a few main fields together with an image.
On a button in each record I have the following code -

Code:
Dim TempID As Integer

Forms!MainOptions!ID = Me!ID

TempID = DLookup("[ID]", "MainTable", "[LatinName]= " & Chr$(34) & Forms!PlantView!PlantViewSub.Form!LatinName & Chr$(34))
Forms!MainOptions!PlantList.Form.Recordset.FindFirst "ID = " & TempID

which makes the selected record's ID match the MainForm's ID and causes the Mainform to display the corresponding full detail. It works fine.

Then, I wanted to use a small image of the selected plant in the continuous form to do the same. So, I copied the above code to the image_Click event (same form). It fails.

It doesn't get the ID of the selected record but it gets the ID of the top of the continuous form's recordsource.

Same code, same form, different control.

Any ideas why it should do that? And is there a way to reinforce the action to get the ID of the selected record?

Thanks
 
Instead of copying the code, what happens if you Call the buttons Click event.
 
Image controls do not receive the focus so clicking on them cannot refer to the current record it is on. It will refer to whatever record happens to be current at the time. Same applies to labels, rectangles, perhaps others

You could add an image to a button or you could place a transparent text box over the image and put your code there
 
Instead of copying the code, what happens if you Call the buttons Click event.
Hi,

On the OnClick event for the image, I used - MoreDetails_Click with the same result.
I have read the comment from CJ_London (below) and think he has supplied a solution which I'm off to try out.
Thanks for your input.
 
Image controls do not receive the focus so clicking on them cannot refer to the current record it is on. It will refer to whatever record happens to be current at the time. Same applies to labels, rectangles, perhaps others

You could add an image to a button or you could place a transparent text box over the image and put your code there
Thanks CJ, I overlaid a transparent button and it worked.

Thanks for the solution.
 

Users who are viewing this thread

Back
Top Bottom