Displaying Images Efficiently

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • OldBirdman
    Contributor
    • Mar 2007
    • 675

    Displaying Images Efficiently

    Each time I move to a different record, I want to display a picture, if available, stored separately from the database. If I have more than one picture, then I will put navagation arrows below the first picture shown.
    I know how to display these pictures without having them embedded in the tables.

    The form is bound to a table with PK=autonum. I have a table=tPicNames
    Code:
    Key        AutoNumber (PK)
    ptr        Long Integer (FK)
    FileName   Text
    PicOrder   Long Integer
    ...
    Therefore,
    Code:
    SELECT FileName FROM tPicNames WHERE ptr=1234 ORDER BY PicOrder
    where 1234 is the current key of the record being displayed.
    So I will need to know if I have zero, one, or many pictures for this Key. If not zero, I will need to get the Text of the first picture (which is the picture name).
    I could do this with a .visible=false ListBox on my form, a form which is hidden, or a recordset (which I don't know how to do.)
    What is fastest?
    What causes least bloat?
    Does it matter if most records have many pictures? If most have only one picture?
    If using a recordset, should it be freed each time new key, therefore new query?
  • ADezii
    Recognized Expert Expert
    • Apr 2006
    • 8834

    #2
    Originally posted by OldBirdman
    Each time I move to a different record, I want to display a picture, if available, stored separately from the database. If I have more than one picture, then I will put navagation arrows below the first picture shown.
    I know how to display these pictures without having them embedded in the tables.

    The form is bound to a table with PK=autonum. I have a table=tPicNames
    Code:
    Key        AutoNumber (PK)
    ptr        Long Integer (FK)
    FileName   Text
    PicOrder   Long Integer
    ...
    Therefore,
    Code:
    SELECT FileName FROM tPicNames WHERE ptr=1234 ORDER BY PicOrder
    where 1234 is the current key of the record being displayed.
    So I will need to know if I have zero, one, or many pictures for this Key. If not zero, I will need to get the Text of the first picture (which is the picture name).
    I could do this with a .visible=false ListBox on my form, a form which is hidden, or a recordset (which I don't know how to do.)
    What is fastest?
    What causes least bloat?
    Does it matter if most records have many pictures? If most have only one picture?
    If using a recordset, should it be freed each time new key, therefore new query?
    Assuming the [FileName] Field cannot be NULL, you can try something like this:
    Code:
    Dim intNumOfPicsPerKey As Integer
    Dim strSQL As String
    Dim lst As ListBox
    
    '[txtCurrentKey] - Text Box on Form that contains the Current Key Value
    
    'Reference to List Box that will contain Filenames ([lstFileNames])
    Set lst = Me![lstFileNames]
    
    lst.ColumnCount = 1
    
    strSQL = "Select tPicNames.FileName From tPicNames Where tPicNames.ptr = " & _
              Me![txtCurrentKey] & " Order By tPicNames.PicOrder;"
    
    If Not IsNull(Me![txtCurrentKey]) Then
      intNumOfPicsPerKey = DCount("*", "tPicNames", "[ptr] = " & Me![txtCurrentKey])
        If intNumOfPicsPerKey > 0 Then
          lst.RowSource = strSQL
        Else
          lst.RowSource = ""
        End If
    End If

    Comment

    • OldBirdman
      Contributor
      • Mar 2007
      • 675

      #3
      This requires a listbox=lstFile Names (hidden?) on the form. It is what I am now doing, and the code looks logically the same.

      The reason for my post is a question of efficiency. After trying to initialize a listbox using a function, I realize that Access doesn't store the information in the listbox beyond those that can be displayed. As there is no ListRows property for listboxes, the number of rows is dependent on the height and the font size, and I am unsure how Access deals with a listbox on a form with a small height.

      I was also wondering if DCount was more efficient than .ListCount, a property of the listbox.

      Code:
      Set lst = Me![lstFileNames] 
      lst.ColumnCount = 1
      If lstFileNames.Co lumnCount were not already 1, would this change it? From A02 Help
      Generally, when you use Set to assign an object reference to a variable, no copy of the object is created for that variable. Instead, a reference to the object is created.
      What is intended here?

      Comment

      • ADezii
        Recognized Expert Expert
        • Apr 2006
        • 8834

        #4
        Originally posted by OldBirdman
        This requires a listbox=lstFile Names (hidden?) on the form. It is what I am now doing, and the code looks logically the same.

        The reason for my post is a question of efficiency. After trying to initialize a listbox using a function, I realize that Access doesn't store the information in the listbox beyond those that can be displayed. As there is no ListRows property for listboxes, the number of rows is dependent on the height and the font size, and I am unsure how Access deals with a listbox on a form with a small height.

        I was also wondering if DCount was more efficient than .ListCount, a property of the listbox.

        Code:
        Set lst = Me![lstFileNames] 
        lst.ColumnCount = 1
        If lstFileNames.Co lumnCount were not already 1, would this change it? From A02 Help What is intended here?
        and I am unsure how Access deals with a listbox on a form with a small height.
        If a List Box cannot accommodate the number of Rows Vertically, Scroll Bars will then appear.
        I was also wondering if DCount was more efficient than .ListCount, a property of the listbox
        I though the concept was to determine how many Pics existed for any given Key, then to branch off from there. It is within this context that DCount() is being used.
        What is intended here?
        Nothing more than how to Set an Object Reference, then set Properties for the Object dynamically.

        Comment

        Working...