command button with picture (1 Viewer)

Siegfried

Registered User.
Local time
Today, 20:59
Joined
Sep 11, 2014
Messages
105
Dear experts,

I have placed on my main menu form command buttons with an picture to access forms/reports.
The picture in the button is gray by default, I created the same button with a orange button and set it hidden
Underneath the command button I put a textbox with label.
The label gives the command button its name and the textbox returns a DCOUNT value when true. If value false then the textbox is not visible.
When the textbox has a true value, then the command button with the orange label becomes visible and the gray one is hidden.
I have attached a picture for visual reference.

When I open the form though there's a runtime delay on the command button of a few seconds before it shows.


Could I overcome this by replacing the picture in the command button instead? If so, how to go about?
Now I'm hidding one command button and making the other one visible...

Below the VBA code I'm using:

Code:
Private Sub Form_Current()

    If Nz(Me!txtBirthday, "") = "" Then
        Me!cmdBirthdayO.Visible = False
        Me!cmdBirthdayG.Visible = True
    Else
        Me!cmdBirthdayO.Visible = True
        Me!cmdBirthdayG.Visible = False
    End If

End Sub
 

Attachments

  • example command button.PNG
    example command button.PNG
    22.5 KB · Views: 172
Last edited:

isladogs

MVP / VIP
Local time
Today, 19:59
Joined
Jan 14, 2017
Messages
18,209
Why use 2 buttons?
The same button can fulfil more than one purpose depending on the circumstances

So you could use one button cmdBirthday and:
1. Set its backcolor, button caption & image in Form_Current if that's important to you
2. Use code in cmdBirthday_Click similar to this

Code:
If Nz(Me!txtBirthday, "") = "" Then
'do whatever code is currently in cmdBirthdayG_Click
Else
'do whatever code is currently in cmdBirthday)_Click
End If
 

theDBguy

I’m here to help
Staff member
Local time
Today, 11:59
Joined
Oct 29, 2018
Messages
21,453
Hi. If you're truly talking about using an image on a button, then you may be stuck with using separate buttons. But if you're just talking about label text and colors, then Colin's suggestion makes more sense.
 

Siegfried

Registered User.
Local time
Today, 20:59
Joined
Sep 11, 2014
Messages
105
Hi Colin,

Thanks again for the swift response and for your help.
I'm using two buttons because I once saw this in an old database example. So I was trying to go with this approach but then encountered the button load delay when opening the form. Which code can I use to change the command button picture? BirtdayGray.jpg for the default no textbox value, and BirthdayOrage.jpg when textbox value?
 
Last edited:

theDBguy

I’m here to help
Staff member
Local time
Today, 11:59
Joined
Oct 29, 2018
Messages
21,453
Hi Colin,

Thanks again for the swift response and for your help.
I'm using two buttons because I once saw this in an old database example. So I was trying to go with this approach but then encountered the button load delay when opening the form. Which code can I use to change the command button picture? BirtdayGray.jpg for the default no textbox value, and BirthdayOrage.jpg when textbox value?
Hi. I see. So, if you're using an external image for your buttons, then it should be possible to change the image dynamically on a single button. I thought you were using the built-in images in Access. I'll let Colin explain the process of changing the image using code. Cheers!
 

isladogs

MVP / VIP
Local time
Today, 19:59
Joined
Jan 14, 2017
Messages
18,209
Last edited:

Users who are viewing this thread

Top Bottom