Problem with getting image to show based on value of a check box. (1 Viewer)

Berkeleygerrell

New member
Local time
Today, 14:16
Joined
Apr 14, 2020
Messages
12
Hi All,

I am struggling to get an image to show based on the value of a check box, im trying to get the image of the approved stamp / Declined stamp to show based on the value of the check boxes below the buttons,

Currently the vba code im am using is this

Where commands are the approve/ decline buttons
Check325 and 328 are the check boxes below
and image 332 is the image of the approve stamp

Any help would be greatly appreciated


Private Sub Command309_Click()
Me.Check325 = True
Me.Check328 = False
End Sub

Private Sub Command310_Click()
Me.Check325 = False
Me.Check328 = True
End Sub

Private Sub Form_Current()
If Me.Check325.Value = True Then
Me.Image332.Visible = True

If Me.Check325.Value = False Then
Me.Image332.Visible = False

End If
End If
End Sub

Private Sub Check325_AfterUpdate()
If Me.Check325.Value = True Then
Me.Image332.Visible = True

If Me.Check325.Value = False Then
Me.Image332.Visible = False

End If
End If
End Sub
 

Attachments

  • Capture.JPG
    Capture.JPG
    32.4 KB · Views: 105

CJ_London

Super Moderator
Staff member
Local time
Today, 14:16
Joined
Feb 19, 2013
Messages
16,607
please use the code box when displaying code to preserve indentation - makes your code easier to read. To do this copy your code from the vba window, click on the </> button and paste into the window that opens.

It would also help if you gave your controls meaningful names

If you indented you would see the problem here

Code:
If Me.Check325.Value = True Then
    Me.Image332.Visible = True

    If Me.Check325.Value = False Then
        Me.Image332.Visible = False

    End If
End If
The code only works when the value is true, false never gets a look in. Much simpler code would just be

Code:
Me.Image332.Visible =Me.Check325

note you do not need .Value - that is the default
 

Berkeleygerrell

New member
Local time
Today, 14:16
Joined
Apr 14, 2020
Messages
12
please use the code box when displaying code to preserve indentation - makes your code easier to read. To do this copy your code from the vba window, click on the </> button and paste into the window that opens.

It would also help if you gave your controls meaningful names

If you indented you would see the problem here

Code:
If Me.Check325.Value = True Then
    Me.Image332.Visible = True

    If Me.Check325.Value = False Then
        Me.Image332.Visible = False

    End If
End If
The code only works when the value is true, false never gets a look in. Much simpler code would just be

Code:
Me.Image332.Visible =Me.Check325

note you do not need .Value - that is the default


Perfect thanks CJ This seems to be working however i have to close and re open the form for this to take effect, is there an additional code i can add to the button to make the form refresh ?
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 21:16
Joined
May 7, 2009
Messages
19,237
on each Checkbox AfterUpdate event, add:

Me.Dirty = False

this will immediately save changes you made.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 21:16
Joined
May 7, 2009
Messages
19,237
I think it should be on the command button click event.
Code:
Private Sub Command309_Click()
Me.Check325 = True
Me.Check328 = False
Me.Dirty  = False
call Form_Current
End Sub

Private Sub Command310_Click()
Me.Check325 = False
Me.Check328 = True
Me.Dirty = False
Call Form_Current
End Sub
 

Berkeleygerrell

New member
Local time
Today, 14:16
Joined
Apr 14, 2020
Messages
12
I think it should be on the command button click event.
Code:
Private Sub Command309_Click()
Me.Check325 = True
Me.Check328 = False
Me.Dirty  = False
call Form_Current
End Sub

Private Sub Command310_Click()
Me.Check325 = False
Me.Check328 = True
Me.Dirty = False
Call Form_Current
End Sub


Perfect thanks , that did the trick
 

isladogs

MVP / VIP
Local time
Today, 14:16
Joined
Jan 14, 2017
Messages
18,216
Do you really need 2 buttons & 2 checkboxes?
Why not just have one checkbox which if ticked indicates approved and if unticked that means declined?
Or just one button whose caption changes from Approve to Decline (or vice versa) when clicked.
Doing either would make coding much simpler
 

Users who are viewing this thread

Top Bottom