Results 1 to 11 of 11
  1. #1
    Join Date
    Apr 2004
    Location
    United Kingdom
    Posts
    56

    Unanswered: Adding text After Update

    Hi Guys,

    I have a text field on a form and after the user has entered in some data I want to put some VBA in there so it will add the text ".jpg" to the end of it.

    Any ideas?

    Many thanks,

    Rusty

  2. #2
    Join Date
    Sep 2003
    Location
    MI
    Posts
    3,713
    Private Sub TextBox_AfterUpdate()

    TextBox.Value=TextBox.Value & ".jpg"

    End Sub

    Next question ...


    Yeah, yeah, yeah, Teddy beat you to it again ...
    Back to Access ... ADO is not the way to go for speed ...

  3. #3
    Join Date
    Apr 2004
    Location
    United Kingdom
    Posts
    56
    Thanks for that it worked a treat...

    But when I delete the text in the field, and want to leave it blank, it still adds the ".jpg". Any ideas on stopping this from happening and leaving my field "null"?

    Thanks,

    Rusty

  4. #4
    Join Date
    Jul 2004
    Posts
    64
    You would need to have an event to evaluate the field then.. Something like

    Private Sub TextBox_AfterUpdate()

    If TextBox <> "" Then
    TextBox.Value=TextBox.Value & ".jpg"
    Else
    Textbox.Value=""
    End if

    End Sub
    Thanks to M Owen for the use of his code...

  5. #5
    Join Date
    Sep 2003
    Location
    MI
    Posts
    3,713
    Quote Originally Posted by Rusty's Way
    Thanks for that it worked a treat...

    But when I delete the text in the field, and want to leave it blank, it still adds the ".jpg". Any ideas on stopping this from happening and leaving my field "null"?

    Thanks,

    Rusty
    Ah ... Mod it to do:

    if TextBox.Value & "" <> "" then TextBox.Value=TextBox.Value & ".jpg"
    Back to Access ... ADO is not the way to go for speed ...

  6. #6
    Join Date
    Sep 2003
    Location
    MI
    Posts
    3,713
    Quote Originally Posted by Bbender27
    You would need to have an event to evaluate the field then.. Something like

    Private Sub TextBox_AfterUpdate()

    If TextBox <> "" Then
    TextBox.Value=TextBox.Value & ".jpg"
    Else
    Textbox.Value=""
    End if

    End Sub
    Thanks to M Owen for the use of his code...
    Lesson for all the kiddies out there: This works MOST OF THE TIME ... BUT, it cannot handle a Null value properly (i.e. Null and "" are not the same) ... To handle BOTH the Null string and an empty string you have to do something like:

    TextBox.Value & "" <> ""
    Back to Access ... ADO is not the way to go for speed ...

  7. #7
    Join Date
    Jul 2004
    Posts
    64
    or what he said

  8. #8
    Join Date
    Jul 2004
    Posts
    64
    Quote Originally Posted by M Owen
    Lesson for all the kiddies out there: This works MOST OF THE TIME ... BUT, it cannot handle a Null value properly (i.e. Null and "" are not the same) ... To handle BOTH the Null string and an empty string you have to do something like:

    TextBox.Value & "" <> ""
    Thanks for that.. How does that account for Null though? Seems strange

  9. #9
    Join Date
    Sep 2003
    Location
    MI
    Posts
    3,713
    Quote Originally Posted by Bbender27
    Thanks for that.. How does that account for Null though? Seems strange
    Because your comparison will FAIL if the value is Null. Like I said: Null and an empty string are not the same ... The comparison I use (and I got it from a guy I worked with years ago ...) basically ANDs an emptry string with the textbox value so that at a minimum you have an empty string (if there's no value) ...
    Back to Access ... ADO is not the way to go for speed ...

  10. #10
    Join Date
    Jul 2004
    Posts
    64
    Yeah, I know about the difference between null and no value, although I did forget to account for it. That is a nifty little trick

  11. #11
    Join Date
    Sep 2003
    Location
    MI
    Posts
    3,713
    Quote Originally Posted by Bbender27
    Yeah, I know about the difference between null and no value, although I did forget to account for it. That is a nifty little trick
    Yep. Better than testing for a Null AND for an empty string ...

    This is also useful for when retrieving/loading info from/into an ADO recordset. Stops all those "Invalid use of Null" error messages ...
    Back to Access ... ADO is not the way to go for speed ...

Posting Permissions

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