none
Can't find the field '|1' referred to in your expression RRS feed

  • Question

  • Hello,

    I am trying to update a table field that will have a url for an image. The function will search a directory & return the proper extension or null:

    With rsTable
    .Edit
    ![Main Image URL] = "/images/product/large/" & rsInStock![item_sku] & DoesImageExistJPGorGIF([item_sku])
    .Update

    The DoesImageExistJPGorGIF() function has the error : Can't find the field '|1' referred to in your expression.

    Here is the function:

    Public Function DoesImageExistJPGorGIF(InventoryId As Long) As String
        Dim strPath As String
        Dim strPix As String
    
        strPath = Nz(gstrPath & InventoryId & ".*", "")
        strPix = Dir(strPath)
    
        If Len(strPix) > 0 Then 'image found
            DoesImageExistJPGorGIF = Right(strPix, 4) 'pass the extension back to the subroutine so it can be used later
        Else 'no image
            DoesImageExistJPGorGIF = ""
        End If 
    End Function

    If I put it in the immediate window for [item_sku] = 16, it returns ".jpg":

    ? DoesImageExistJPGorGIF(16)
    .jpg

    Any help greatly appreciated!

    Thank you,

    Albert


    Albert S

    Friday, June 23, 2017 9:11 PM

Answers

  • ![Main Image URL] = "/images/product/large/" & rsInStock![item_sku] & DoesImageExistJPGorGIF([item_sku])

    Albert S

    Hi Albert,

    Thanks. Did you need to use the following syntax for your function?

    DoesImageExistJPGorGIF([rsInStock]![item_sku])

    • Marked as answer by Albert S Saturday, June 24, 2017 1:35 AM
    Saturday, June 24, 2017 1:02 AM

All replies

  • Hi Albert,

    Which line gets highlighted when you go to Debug?

    Friday, June 23, 2017 9:28 PM
  • strPath = Nz(gstrPath & InventoryId & ".*", "")

    Hi Albert,

    Does  gstrPath  have the right value?

    Imb.

    Friday, June 23, 2017 9:37 PM
  • ![Main Image URL] = "/images/product/large/" & rsInStock![item_sku] & DoesImageExistJPGorGIF([item_sku])

    Albert S

    Friday, June 23, 2017 9:58 PM
  • Hello,

    Here is the constant:

    Const gstrPath = "\\DH6C8CZ1\images\"

    Funciton seems to work ok with an update query. Maybe trying to pass the null or "" back might be causing it?

    Thanks,

    Albert


    Albert S

    Friday, June 23, 2017 10:01 PM
  • ![Main Image URL] = "/images/product/large/" & rsInStock![item_sku] & DoesImageExistJPGorGIF([item_sku])

    Albert S

    Hi Albert,

    Thanks. Did you need to use the following syntax for your function?

    DoesImageExistJPGorGIF([rsInStock]![item_sku])

    • Marked as answer by Albert S Saturday, June 24, 2017 1:35 AM
    Saturday, June 24, 2017 1:02 AM
  • I had a feeling it was something I overlooked. 

    That did the trick.

    Thank you,

    Albert


    Albert S

    Saturday, June 24, 2017 1:35 AM
  • Hi Albert, Glad to hear you got it to work. Good luck with your project.
    Saturday, June 24, 2017 3:35 AM