• ** There has been a recent site upgrade. Please clear your browser cache to avoid issues. **
  • New forum feature - post voting and best solution

    Check out this thread for the details: https://www.access-programmers.co.uk/forums/threads/new-forum-feature-post-voting-and-best-answer.314134/

    This new feature looks great to me! :)

  • We now have 3 forum themes

    Go for the default (light) theme, Shades of Grey or Shades of Blue. I just added the Blue one.

    The thread about it is here: https://www.access-programmers.co.uk/forums/threads/new-forum-theme-shades-of-blue.314136/

Change Order Picture Attachments are Displayed in Form (1 Viewer)

SteveClarkson

Registered User.
Local time
Today, 13:00
Joined
Feb 1, 2003
Messages
439
Hello,

Long time, no post!

I have a form with an Attachment field on it - this field is used to store user photographs. Once in a while, these pictures are updated, but the old ones are retained too. They follow the naming convention of: CCYY_MM_DD_HH_MM_SS.jpg

When there is a single photo in there, it's great - you open up that users record, and it shows their photo, lovely.

If they have a newer picture added, because of the naming convention, they are ordered from lowest to highest - and with the naming convention in use, this puts the newest photos at the bottom of the list - and so the "default" picture shown is actually the oldest one.

I can't seem to find a way to 'encourage' Access to change the order it displays these attachments in - any ideas?

Running Access for Office 365 (v16)

Thank you,

Steve
 

arnelgp

error reading drive A:
Local time
Today, 21:00
Joined
May 7, 2009
Messages
10,566
you can force it to show the last attachment.
on design view of your form, click on the attachment control
on its Event (On Attachment Current):
Code:
Private Sub attConttrol_AttachmentCurrent()
If Me.attControl.AttachmentCount > 0 Then
    Me.attControl.CurrentAttachment = Me.attControl.AttachmentCount - 1
End If
End Sub
 

SteveClarkson

Registered User.
Local time
Today, 13:00
Joined
Feb 1, 2003
Messages
439
Thank you, arnelgp! That looked like a winner... except that once implemented, when I open the form, I'm now getting an Error 28 - out of stack space? :(
 

Gasman

Enthusiastic Amateur
Local time
Today, 13:00
Joined
Sep 21, 2011
Messages
6,818
Perhaps it should be > 1 ?
 

arnelgp

error reading drive A:
Local time
Today, 21:00
Joined
May 7, 2009
Messages
10,566
another alternative is use the Form's Current event to Move Forward the Attachment:
Code:
Private Sub Form_Current()
    Dim i As Integer
    On Error GoTo exit_sub
    i = Me.attachmentControl.AttachmentCount
    If i > 0 Then
        Do While i > 0
            Me.attachmentControl.Forward
            i = i - 1
        Loop
    End If
exit_sub:
    On Error GoTo 0
    
End Sub
 

arnelgp

error reading drive A:
Local time
Today, 21:00
Joined
May 7, 2009
Messages
10,566
another alternative is use the Form's Current event to Move Forward the Attachment:
Code:
Private Sub Form_Current()
    Dim i As Integer
    On Error GoTo exit_sub
    i = Me.attachmentControl.AttachmentCount
    If i > 0 Then
        Do While i > 0
            Me.attachmentControl.Forward
            i = i - 1
        Loop
    End If
exit_sub:
    On Error GoTo 0
    
End Sub
 

SteveClarkson

Registered User.
Local time
Today, 13:00
Joined
Feb 1, 2003
Messages
439
Thank you both,

I ended up putting this:
Code:
If Me.attControl.AttachmentCount > 1 Then
    Me.attControl.CurrentAttachment = Me.attControl.AttachmentCount - 1
End If

Into the Forms OnCurrent event - which appears to do the job!
 

SteveClarkson

Registered User.
Local time
Today, 13:00
Joined
Feb 1, 2003
Messages
439
another alternative is use the Form's Current event to Move Forward the Attachment:

Oh, I think this is prettier... I've put that in, and it does the same job... so I'll go with that one!

Thanks arnelgp!
 

Gasman

Enthusiastic Amateur
Local time
Today, 13:00
Joined
Sep 21, 2011
Messages
6,818
Oh, I think this is prettier... I've put that in, and it does the same job... so I'll go with that one!

Thanks arnelgp!
Pretty does not come into it, it is code after all. :)

I'd go with 3 lines of code rather than 11 anytime. :D
 

Users who are viewing this thread

Top Bottom