null problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Kaosu
    New Member
    • Oct 2007
    • 19

    null problem

    I am trying to get the database to display the picture of the person on the current record and if not to display the company logo.

    At the moment I cant get the form to recognise the value as Null and not try and display a picture that does not exist bringing up a 2220 runtime error.



    Private Sub Form_Current()

    imgTxt.Value = "W:\trainin g database\Pictur es\" & SQSID & ".jpg"

    If imgTxt.Value = Null Then
    Pic.Picture = "W:\trainin g database\Pictur es\sqs.bmp"
    Else
    Pic.Picture = imgTxt.Value
    End If

    End Sub
  • Jim Doherty
    Recognized Expert Contributor
    • Aug 2007
    • 897

    #2
    Originally posted by Kaosu
    I am trying to get the database to display the picture of the person on the current record and if not to display the company logo.

    At the moment I cant get the form to recognise the value as Null and not try and display a picture that does not exist bringing up a 2220 runtime error.



    Private Sub Form_Current()

    imgTxt.Value = "W:\trainin g database\Pictur es\" & SQSID & ".jpg"

    If imgTxt.Value = Null Then
    Pic.Picture = "W:\trainin g database\Pictur es\sqs.bmp"
    Else
    Pic.Picture = imgTxt.Value
    End If

    End Sub

    Change
    Code:
     If imgTxt.Value = Null
    to
    Code:
     If IsNull(Me!img) Then

    Comment

    • Kaosu
      New Member
      • Oct 2007
      • 19

      #3
      the imgTxt is actualy a txtbox with the path for the img.
      i changed the code to

      If IsNull(Me!imgTx t) Then

      but its still skipping the null, bring up the runtime error and stating that...

      imgTxt = "W:\trainin g database\Pictur es\" & SQSID & ".jpg"
      ......

      Pic.Picture = imgTxt.Value


      is missing

      Comment

      • Jim Doherty
        Recognized Expert Contributor
        • Aug 2007
        • 897

        #4
        Originally posted by Kaosu
        the imgTxt is actualy a txtbox with the path for the img.
        i changed the code to

        If IsNull(Me!imgTx t) Then

        but its still skipping the null, bring up the runtime error and stating that...

        imgTxt = "W:\trainin g database\Pictur es\" & SQSID & ".jpg"
        ......

        Pic.Picture = imgTxt.Value

        is missing
        If its skipping over the true part of the IF expression then it means it isnt null

        leave the word VALUE out just refer to the control Me!imgtxt

        You might want to consider also doubling up on the first if statement to take account of any zero length string

        If IsNull(Me!imgTx t) Or Me!imgTxt ="" THEN

        Wheres is the value SQSID coming from?and also when using a textbox or any other control on a form get into the habit of including a reference to the form on which the textbox is mounted using the ME keyword

        Regards

        Jim

        Comment

        • Kaosu
          New Member
          • Oct 2007
          • 19

          #5
          Originally posted by Jim Doherty
          Wheres is the value SQSID coming from?and also when using a textbox or any other control on a form get into the habit of including a reference to the form on which the textbox is mounted using the ME keyword
          "W:\trainin g database\Pictur es\" & SQSID & ".jpg"

          "SQSID" is the name of the key field.
          each persons picture is numbered with their company id so that when the picture is put into the folder it will automatically show up when scrolling through the records (if i ever get it to work).

          just tested it and its still not working with

          If IsNull(Me!imgTx t) Or Me!imgTxt ="" THEN

          its still trying to find the path of a file that doesn't exist.
          is null even the right statement to be using?

          i highlighted the Me!imgTxt and saw

          Me!imgTxt = "W:\trainin g database\Pictur es\3.jpg"
          (i only have 2 jpg's in the folder atm so 3 does not exist)


          and i think the problem is that even though the file does not exist the path is still stored in the txtbox.
          is there another way of checking if that file exists or not?

          Comment

          • Kaosu
            New Member
            • Oct 2007
            • 19

            #6
            after another hard days work browsing google i got it to work.

            Private Sub Form_Current()

            If Dir("W:\trainin g database\Pictur es\" & SQSID & ".jpg", vbNormal) <> "" Then
            Me!imgTxt = "W:\trainin g database\Pictur es\" & SQSID & ".jpg"
            Else
            Me!imgTxt = ""
            End If

            If IsNull(Me!imgTx t) Or Me!imgTxt = "" Then
            Pic.Picture = "W:\trainin g database\Pictur es\sqs.bmp"
            Else
            Pic.Picture = imgTxt

            End If

            End Sub


            thx for ur input jim

            Comment

            Working...