Solved Show/Hide an image depends the value of a textbox (1 Viewer)

IvaanGarciia

Member
Local time
Today, 08:42
Joined
Mar 5, 2020
Messages
37
Hi AWF,

I'm attending to show or hide an image depens the value of a textbox... I got 2 images that must be switching.. Actually I've used a code posted in this forum but unsuccessfully.

Private Sub Form_Current()
If Me.Num_ecu = "TC" Then
Me.TrackerIMG.Visible = True
Me.ForkliftIMG.Visible = False
Else
Me.ForkliftIMG.Visible = True
Me.TrackerIMG.Visible = False
End If
End Sub

1584114876985.png


When I add the Id_asset the num_ecu textbox shows a value, depends those values, it should show/hide the images..

Regards,
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 08:42
Joined
Aug 30, 2003
Messages
36,124
The current event fires when the form loads and when the user changes records. You'd want the same code in the after update event of Me.Num_ecu.
 

IvaanGarciia

Member
Local time
Today, 08:42
Joined
Mar 5, 2020
Messages
37
The current event fires when the form loads and when the user changes records. You'd want the same code in the after update event of Me.Num_ecu.
Hey baldy, thanks for assistance me, I've changed to after update to the Num_ecu, but still didn't work.
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 08:42
Joined
Aug 30, 2003
Messages
36,124
The code looks okay offhand. Are you sure of the contents of that control? Can you attach the db here?
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 08:42
Joined
Aug 30, 2003
Messages
36,124
There is no code in the current event. I copied it to the current event and it worked as expected. The code in the after update event wouldn't work because the control is locked/disabled.
 

IvaanGarciia

Member
Local time
Today, 08:42
Joined
Mar 5, 2020
Messages
37
But I need that this textbox stay disable is just for visual id, put them as you tell me but not have the same behavior
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 08:42
Joined
Aug 30, 2003
Messages
36,124
That's fine, as I said the code works in the current event so as you move through records the images change as appropriate. You had it in the change event of the textbox, not the current event of the form.
 

IvaanGarciia

Member
Local time
Today, 08:42
Joined
Mar 5, 2020
Messages
37
Is there a way that effect the event with the txtbox disable? I've seen that to the event work I need to hit the textbox, but want that the change was automatic.
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 08:42
Joined
Aug 30, 2003
Messages
36,124
The current event works as-is, I don't have to "hit the textbox" to see the images change, just scroll through records.. The update event won't work if the user isn't changing the value. If it changes because of a change to another control, use that control's after update event.
 

IvaanGarciia

Member
Local time
Today, 08:42
Joined
Mar 5, 2020
Messages
37
I didn't why but in my case I neet to write something in the textbox or hitting in it to show the picture
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 08:42
Joined
Aug 30, 2003
Messages
36,124
You added the code the the current event of the form? All I'm doing is changing the record selector at the bottom:

1584123326809.png

1584123338747.png
 

IvaanGarciia

Member
Local time
Today, 08:42
Joined
Mar 5, 2020
Messages
37
So, let me explain the process in my head XD, when I put the user ID pass to asset when I added the asset the Num_ecu value show in the textbox in the picture case is "TC" when that textbox show a value I'd like to the pictures shows/hide. Not when I pass through the recors, indeed I'll block the option of pass through records.

Thanks
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 08:42
Joined
Aug 30, 2003
Messages
36,124
Maybe I'm just being dense. There is no other code in the lease form, so nothing would change the value in Num_ecu when you entered a value in Num_emp or Id_asset. If it did, that would be the place to the code to make the appropriate image visible. If you're talking about a "search" feature, the current event would handle the form going to a different record.

If that's not it, can you describe step-by-step the actions you would take so I can recreate them?
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 08:42
Joined
Aug 30, 2003
Messages
36,124
Glad you got it sorted. I hadn't noticed the form was bound to a query, so the value would update as you entered other values.
 

Users who are viewing this thread

Top Bottom