Consulting

Results 1 to 15 of 15

Thread: If Txtbox equals Chr then Show Image

  1. #1
    VBAX Expert
    Joined
    Apr 2007
    Location
    Orlando, FL
    Posts
    751
    Location

    If Txtbox equals Chr then Show Image

    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?

  2. #2
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    not if you embed(insert-picture) them and make their visibility false.....I'm guessing.
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  3. #3
    VBAX Expert
    Joined
    Apr 2007
    Location
    Orlando, FL
    Posts
    751
    Location
    So if the visibility is false I can't do it?

  4. #4
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    When the form starts you want your picture to be hidden so use the initialize statment:
    [VBA]Private Sub UserForm_Initialize()
    Image1.Visible = False
    End Sub[/VBA]

    then for the textbox code....something like:
    [VBA]Private Sub Txtbox1_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean)
    If Txtbox1.Text = "chevy" Then Image1.Visible = True
    End Sub[/VBA]
    see attached.
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  5. #5
    VBAX Expert
    Joined
    Apr 2007
    Location
    Orlando, FL
    Posts
    751
    Location
    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?

  6. #6
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    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...
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  7. #7
    VBAX Expert
    Joined
    Apr 2007
    Location
    Orlando, FL
    Posts
    751
    Location
    So I can set something like this
    [VBA]
    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
    [/VBA]

  8. #8
    VBAX Expert
    Joined
    Apr 2007
    Location
    Orlando, FL
    Posts
    751
    Location
    I don't think it's that simple. Is it?

  9. #9
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    see if this gets you a start...
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  10. #10
    VBAX Expert
    Joined
    Apr 2007
    Location
    Orlando, FL
    Posts
    751
    Location
    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
    [vba]
    ImageFedEx.Visible = True & ImageUPS.Visible = False
    [/vba]
    But looks good in yours. Maybe I missed something. Any Ideas.

  11. #11
    VBAX Expert
    Joined
    Apr 2007
    Location
    Orlando, FL
    Posts
    751
    Location
    Ok I played around with it and got it to work.
    I got this

    [VBA]If MyLen = 12 Then ImageFedEx.Visible = True
    If MyLen = 9 Then ImageUPS.Visible = True[/VBA]

    I removed the [VBA]& Visible = False[/VBA] images.

    will do further testing.

  12. #12
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    It was just a start in the right direction Em.....
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  13. #13
    VBAX Expert
    Joined
    Apr 2007
    Location
    Orlando, FL
    Posts
    751
    Location
    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.

  14. #14
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    try another picture.....
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  15. #15
    VBAX Expert
    Joined
    Apr 2007
    Location
    Orlando, FL
    Posts
    751
    Location
    Ok But how would the script go to check if the other 3 are False to give me the new picture?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •