Solved View button for each document on continuous form (1 Viewer)

allen675

Member
Local time
Today, 11:50
Joined
Jul 13, 2022
Messages
124
Hi fellow Forum'ers,

I have a tabbed control containing a subform. On the 'Contact Proof' list I have a list of all the proofs attached to the record, this is a continuous subform. I have it working almost the way I want it, however, you will note from the screenshot attached that I also have a view option. Currently I am able to double click on the file name and this opens the file, perfect. But I also want the end user to be able to click the view label to be able to perform the same operation i.e. open the document. I have tried Me.FileName.SetFocus argument, however, this doesnt work but I may be barking up the wrong tree as the 'view' button I assume wouldn't know which one to set focus to in a continuous form?.

A bit of detail to help whoever looks at/helps me with this thread/dilemma: I have a Windows folder under the database called 'ContactProofs' and run some FileSystemObject code to copy files from wherever the end user saves them before uploading (pasting to 'ContactProofs' folder) to the DB. The code doesnt allow for the same filename each time, so each record File Name will have a unique name. Behind the 'FileName' textbox I've hidden another textbox which contains the 'ProofOfContactID'. I'm not sure I need this but its there if required.

I hope the above makes sense? Please help!
 

Attachments

  • Capture.PNG
    Capture.PNG
    8.8 KB · Views: 108

plog

Banishment Pending
Local time
Today, 05:50
Joined
May 11, 2011
Messages
11,638
If you click on an object, it immediately gets the focus. Setting the focus via code to another place just places the focus there. It does not capture the prior clicks to that object. If you clicked on View and its code set the focus to another spot, if you clicked again without moving the mouse all that will happen is you move the focus back to wherever the mouse is. It would be like a manual infinite loop.

Presumably you have code on the file name field, most likely an OnClick event. Copy that code and make an OnClick event for your label. That way it will do what you want.

As for your filenames they should simply be the primary key of the record they belong to. Let's save you are saving the document "Testing.doc". It gets a record in your table with the primary key ID of 73. When it gets moved to your documents file its name will become 73.doc, which allows the database to always know which record it belongs to. Further it eliminates the need for you to make sure you are giving it a unique name because the ID value is guaranteed to be unique.
 

allen675

Member
Local time
Today, 11:50
Joined
Jul 13, 2022
Messages
124
Presumably you have code on the file name field, most likely an OnClick event. Copy that code and make an OnClick event for your label. That way it will do what you want.
Hi Plog,

Thank you for your suggestion.

I have tried your above suggestion and unfortunately copying the code for the click event on file name to the view label does not work!

Regards
 

plog

Banishment Pending
Local time
Today, 05:50
Joined
May 11, 2011
Messages
11,638
Define 'not work'. Nothing happens? Unexpected results? Error message? It made your wife leave you for a younger man? Give me something to go on.

Also, please post your code. Actually a whole copy of your database would be best.
 

allen675

Member
Local time
Today, 11:50
Joined
Jul 13, 2022
Messages
124
Does nothing!

I'll upload them code when back home in a bit.

May I ask why it is necessary for you to see the whole database?
 

plog

Banishment Pending
Local time
Today, 05:50
Joined
May 11, 2011
Messages
11,638
Its not--its just usually easier for people to throw the whole thing online.

If you can simply provide the form and the datasource the form is based on that should be enough. The datasource can even be empty--I'll add fake data to make the form work. You can create a new blank database, copy in the form and just the table structure of the table that will do it.
 

allen675

Member
Local time
Today, 11:50
Joined
Jul 13, 2022
Messages
124
Apology for the delay.

This the code behind the double click event on 'FileName' which as previously stated I've tried behind the click event of the 'View' label:

Code:
    Dim sBasePath As String
    Dim sBaseFileName As String
    
    sBasePath = CurrentProject.Path & "\ContactProofs\"
    If IsNull(Me.FileName) Then Exit Sub
    sBaseFileName = Me.FileName
    Application.FollowHyperlink sBasePath & sBaseFileName, , True

May seem like a silly question how can I upload just the form and datasource without the entire DB?
 

plog

Banishment Pending
Local time
Today, 05:50
Joined
May 11, 2011
Messages
11,638
Yes you can just upload those 2 things. The datasource can even be empty.

I don't see anything wrong with the code you posted, so I will need to try it for myself if you can upload.
 

allen675

Member
Local time
Today, 11:50
Joined
Jul 13, 2022
Messages
124
CJ_London thank you. I've done my best but cant guarantee I've done it properly! @plog please find attached 👍
 

plog

Banishment Pending
Local time
Today, 05:50
Joined
May 11, 2011
Messages
11,638
I don't see the issue. I added fake data to ContactProofT. Then I opened CopyOfContactProofF, when I click the file name in the record it tried to open a file. When I clicked the View label it tried to open the exact same file. No issue.
 

allen675

Member
Local time
Today, 11:50
Joined
Jul 13, 2022
Messages
124
Interesting, I have you tried opening it from within the existing/new lead forms where end users will be operating it?
 

allen675

Member
Local time
Today, 11:50
Joined
Jul 13, 2022
Messages
124
It's also worth noting that if you single click the FileName first then the view button it works but if you click the FileName field of a different file and then click the view button on about file it does not work!
 

plog

Banishment Pending
Local time
Today, 05:50
Joined
May 11, 2011
Messages
11,638
You should change it from a label to a button. A label is unable to obtain the focus. That means although you click on a specific rows View label that row doesn't obtain the focus and VBA doesn't know which file you are on and uses the last loaded one.

A button can obtain the focus and when it does it knows which row to use and will open the correct file.
 

allen675

Member
Local time
Today, 11:50
Joined
Jul 13, 2022
Messages
124
You should change it from a label to a button. A label is unable to obtain the focus. That means although you click on a specific rows View label that row doesn't obtain the focus and VBA doesn't know which file you are on and uses the last loaded one.

A button can obtain the focus and when it does it knows which row to use and will open the correct file.
Plog,

That makes sense I shall give that a go and let you know how I get on.

Thank you
 

allen675

Member
Local time
Today, 11:50
Joined
Jul 13, 2022
Messages
124
Plog,

That makes sense I shall give that a go and let you know how I get on.

Thank you
Would you look at that, worked a treat 👍

Made button and border transparent and left label behind as this gives the same appearance that I was originally looking for.

Thank you for all your help
 

Users who are viewing this thread

Top Bottom