PDA

View Full Version : If Txtbox equals Chr then Show Image



Emoncada
05-09-2007, 12:15 PM
I would like a image to be change to visible if a txtbox equals so many characters.
So
If txtbox1 = 12 Digits long then Image1.Visible = True
If Txtbox1 = 9 Digits long then Image2.Visible = True
If Txtbox1 = "Pick Up" then Image3.Visible = True

Can I do that or would I need to call file. LoadPicture?

lucas
05-09-2007, 03:37 PM
not if you embed(insert-picture) them and make their visibility false.....I'm guessing.

Emoncada
05-09-2007, 04:59 PM
So if the visibility is false I can't do it?

lucas
05-09-2007, 05:33 PM
When the form starts you want your picture to be hidden so use the initialize statment:
Private Sub UserForm_Initialize()
Image1.Visible = False
End Sub

then for the textbox code....something like:
Private Sub Txtbox1_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean)
If Txtbox1.Text = "chevy" Then Image1.Visible = True
End Sub
see attached.

Emoncada
05-09-2007, 05:48 PM
Ok that can work only thing the txtbox is alway going to me different numbers. So if the number is 12 digits long then I want Image1, if it's 9 numbers long I want Image2. Your vb can work for the third image. how can I make it work for the first 2 images?

lucas
05-09-2007, 05:52 PM
I would add the other to set to false in the initialize statement and then set up beforeupdate code for each of the textboxes if thats how you want to show them...you could use that code in a button...

Emoncada
05-09-2007, 06:04 PM
So I can set something like this

Private Sub TxtTrack1_AfterUpdate()
If TxtTrack1 <> Chr(12) Then
Image1.Visible = True
End If
IF TxtTrack1 <> Chr(9) Then
Image2.Visible = True
End If
End Sub

Emoncada
05-09-2007, 06:07 PM
I don't think it's that simple. Is it?

lucas
05-09-2007, 09:43 PM
see if this gets you a start...

Emoncada
05-10-2007, 06:44 AM
For some strange reason It works great on yours but when I use it in mine It doesn't. I get the Run-Time Error '13': Type mismatch
Then Highlights this part

ImageFedEx.Visible = True & ImageUPS.Visible = False

But looks good in yours. Maybe I missed something. Any Ideas.

Emoncada
05-10-2007, 08:19 AM
Ok I played around with it and got it to work.
I got this

If MyLen = 12 Then ImageFedEx.Visible = True
If MyLen = 9 Then ImageUPS.Visible = True

I removed the & Visible = False images.

will do further testing.

lucas
05-10-2007, 08:24 AM
It was just a start in the right direction Em.....

Emoncada
05-10-2007, 09:51 AM
Thanks A lot Lucas. Do you know how I can add something to say if neither 3 are true then to give me a MsgBox "Please Check Tracking".
I've been trying but im stuck now.

lucas
05-10-2007, 12:12 PM
try another picture.....

Emoncada
05-10-2007, 12:14 PM
Ok But how would the script go to check if the other 3 are False to give me the new picture?