Addressing controls in a form (1 Viewer)

sja13

Professional Idiot
Local time
Today, 20:58
Joined
May 3, 2017
Messages
63
Hi...

The Background
I have a Form, on which there is an Image.
The Image is either a photo of an object, or a "default" photo saying "Awaiting Image".
The photos are NOT embedded - they are paths to images in sub-folders.

The Requirement
I want to allow the User to double-click the photo to get the option to either
  • replace the photo with another one (i.e. "Awaiting Image" changes to a photo, or
  • change the existing photo to a different one, or
  • change the existing photo to "Awaiting Image"
To facilitate this I designed a "pop-up" Form, with a Frame, within which I used the Wizard to create 3 Radio buttons (Add, Change, and Remove).

I wanted to be able to "grey-out" certain Radio buttons in certain situations (e.g. If the Image is "Awiting Image", disable the "Remove" button.

The Problem
I'm trying to set up the Radio buttons in a subroutine called from the Image's "Double-click" code, but I can't find the right code to access them.
I issue
Code:
  DoCmd.OpenForm "frmImage", acNormal
then try to access the controls on "frmImage"
I've tried several ways, the current being (where strPath is the path to the image, gstrA_I_Full is the path to the "Awaiting Image jpg, and the Radio buttons on the pop-up form frmImage are optAdd, optEdit and optDel)
Code:
 With CurrentProject.AllForms("frmImage")
    Select Case strPath
      Case Is = "", Is = gstrA_I_Full 'No Del
        .Controls("optAdd").Enabled = True
        .Controls("optEdit").Enabled = True
        .Controls("optDel").Enabled = False
      Case Else 'No Add
        .Controls("optAdd").Enabled = False
        .Controls("optEdit").Enabled = True
        .Controls("optDel").Enabled = True
    End Select
  End With
I've also tried to reference the frmImage controls with
Code:
With Forms!frmImage
and
Code:
Forms!frmImage!optEdit.Controls("optAdd").Enabled = True
and variants of the above replacing some or all of the "."s with "!"s and vice-versa.
I either get "Object doesn't support this property or method" or "Cannot find the named object" or variants thereof.

Can any kind soul point me in the right direction?
Is it because it's a pop-up Form? Should I be approaching this in some other way?
Please help if you can....
 

Ranman256

Well-known member
Local time
Today, 15:58
Joined
Apr 9, 2015
Messages
4,337
Add and change are the same thing,so you only need ADD.
Remove : just has to null the file path....
TxtPath=null

Controls are just referenced directly....
Forms!myForm!cboBox= "bob"
 

Minty

AWF VIP
Local time
Today, 20:58
Joined
Jul 26, 2013
Messages
10,380
Presumably you already know before opening the popup form if you are awaiting image or there is an existing image as you can easily interrogate the existing path filename.

So based on that simply pass something to the popup form using OpenArgs to determine what options to enable?
 

sja13

Professional Idiot
Local time
Today, 20:58
Joined
May 3, 2017
Messages
63
Thanks Ranman256 and Minty.

I know I really only need two options, (which is why the SELECT CASE has only two conditions), but I wanted to keep the standard "Add/Delete/Edit" cluster for my Users.
I'll happily make the change if I have to, but my problem is (at the moment) working out the syntax to access the controls.

Ranman256 - I understand your comment
"Controls are just referenced directly....
Forms!myForm!cboBox= "bob""
but what I'm trying to do (whether it's sensible or not) is to work out the correct syntax for
Code:
Forms!myForm!myOpt.Enabled = False

it's how to add the Property "Eanbled" to the Object I'm struggling with.

In the meantime UI'l explore Minty's OpenArgs suggestion....
 

Ranman256

Well-known member
Local time
Today, 15:58
Joined
Apr 9, 2015
Messages
4,337
options are not handled that way.
you must set the FRAME holding the options, THATS what gets the value. The buttons only show the result.

if FRAME1 holds the 3 options, then
FRAME1.value = 2
(will set the button 2 active)
 

MarkK

bit cruncher
Local time
Today, 12:58
Joined
Mar 17, 2004
Messages
8,194
I would put this code on frmImage in a public method...
Code:
Public Sub ResetForm
   Select Case Me.PathToImage
      Case "", gstrA_I_Full 'No Del
         Me.optAdd.Enabled = True
         Me.optEdit.Enabled = True
         Me.optDel.Enabled = False
      Case Else 'No Add
         Me.optAdd.Enabled = False
         Me.optEdit.Enabled = True
         Me.optDel.Enabled = True
    End Select
End Sub
...and then call it from wherever, like...
Code:
const FN as string = "frmImage"
docmd.openform FN
forms(FN).ResetForm
hth
Mark
 

sja13

Professional Idiot
Local time
Today, 20:58
Joined
May 3, 2017
Messages
63
Ah! The Frame! Thanks Ranman256 - I guess I'm just too used to Excel VBA!
Now working fine, based on OpenArgs functionality.
Would have replied earlier, but I was struggling to keep the pop-up form "paused" 'till I discovered acDialog as the Windows mode.

Thanks again to ALL contributors....
 

Users who are viewing this thread

Top Bottom