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

SteveClarkson

Registered User.
Local time
Today, 18:46
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

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 01:46
Joined
May 7, 2009
Messages
19,227
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, 18:46
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, 18:46
Joined
Sep 21, 2011
Messages
14,217
Perhaps it should be > 1 ?
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 01:46
Joined
May 7, 2009
Messages
19,227
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

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 01:46
Joined
May 7, 2009
Messages
19,227
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, 18:46
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, 18:46
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, 18:46
Joined
Sep 21, 2011
Messages
14,217
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