Forum

User form - Adding ...
 
Notifications
Clear all

User form - Adding a PNG and a path to the file

14 Posts
2 Users
0 Reactions
441 Views
(@briantitus)
Posts: 8
Active Member
Topic starter
 

Hi MOH community

First off - what I know about VBA is scary.

I have been watching the video on creating a userform that Philip uploaded in 2015. I can amend this workbook to suite my needs. Additional feature I wou like to add is when the expense entry has a "before" file to be attached and then when it is approved and "after" and when it is paid a "paid" stamp.

Is it possible to browse and upload these stages of the expenses to the userform?

Then when you click on the hyperlink of the file it will open the .png and also take you to the file location.

All of this information will be stored on my hard drive and won't be shared across a network.

I thought that this video about the hyperlink will solve my ask but not quit sure how to make the upload feature work or even opening the file location.

I have attached the latest file from Philip - I have not changed anything on this file - just studying it to see how I could incorporating the functionality above.

The attached expenses file is where I have started to make the amendments.

Hope that is in order.

Regards

Brian

 
Posted : 11/08/2020 4:39 am
(@catalinb)
Posts: 1937
Member Admin
 

Hi Brian,

The stages are not uploaded to user form, I guess you just want to display a link to those files in the userform.
Add a label with the file full path, then for that label, the code should be:

Private Sub Label1_Click()

Shell "explorer.exe " & Label1.Caption

End Sub

When you will click that label in userform, the file should open.
The file you have uploaded cannot be downloaded so I was not able to modify your file.

 
Posted : 18/08/2020 11:12 pm
(@briantitus)
Posts: 8
Active Member
Topic starter
 

Hi Catalin

I have progressed this a little. I have attached the latest version of what I am trying to build.

Loading pictures: In this user form I have placeholders for 4 charts. Through the good old internet - I have a code in there to get the first picture loaded and it works. Now do I have to create a private sub get image 3 more times to get the images for the other 3 charts? chart 1 and chart 2 could be in the same folder on my workbook. Chart 3 will be in its own folder and Chart 4 will be in its own folder. Alternatively is there some clever way to make the existing private sub get image function loop through each chart?

Chart location: I have a label working which opens the folder where the chart is saved. Your suggestion seems better in that I don't have to look for that chart in the folder if I want to view it. Thing is I don't know how to edit the existing code with yours please help.

Formulas: I have formulas in my workbook - orange highlighted cells - which work fine when I work in the table in the workbook. However when I open the useform and then close it - the formulas get overwritten. Have you come across this before?

Regards

Brian

 
Posted : 19/08/2020 5:27 am
(@catalinb)
Posts: 1937
Member Admin
 

Added in the file attached a new version of GetImage procedure.

If you don't want code to overwrite table formulas, then just remove those lines of code that are writing in those columns:

' .Cells(1, 9) = txtEntryFilledShares.Value ' add an apostrophy at the beginning of this line to disable it
 
Posted : 19/08/2020 11:29 am
(@briantitus)
Posts: 8
Active Member
Topic starter
 

Hi Catalin

When I go to utilise the form I get the following error message:

Compile error, Sub or function not defined and ShowImages is highlighted.

 

Private Sub UserForm_Initialize()

Set TradeJournalTable = ActiveSheet.ListObjects("TradeJournal")

'Initialise for empty table
ChangeRecord.Min = 0
ChangeRecord.Max = 0

CurrentRow = TradeJournalTable.ListRows.Count

If CurrentRow > 0 Then

ChangeRecord.Min = 1
ChangeRecord.Max = TradeJournalTable.ListRows.Count

'Load last record into form
PopulateForm TradeJournalTable.ListRows(TradeJournalTable.ListRows.Count).Range
TradeJournalTable.ListRows(TradeJournalTable.ListRows.Count).Range.Select

UpdatePositionCaption

Else

RecordPosition.Caption = "0 of 0"

End If

ShowImages

End Sub

 
Posted : 20/08/2020 1:51 pm
(@catalinb)
Posts: 1937
Member Admin
 

Just delete that line, that procedure does not exist anymore.

 
Posted : 20/08/2020 11:00 pm
(@briantitus)
Posts: 8
Active Member
Topic starter
 

Hi Catalin

Thanks for the above.

Can you please help with the Getimage sub.

I think the right and value functions is not creating the correct number of either 1,2,3 or 4 to append to image later in the sequence.

The image is not loading nor do I get an error message.

Thanks in advance

brian

 
Posted : 23/08/2020 2:13 am
(@catalinb)
Posts: 1937
Member Admin
 

This line should be updated:
ChName = Right(Ctl.Name, Len(Ctl.Name) - InStr(Ctl.Name, "Chart"))

replace it with:
ChName = Right(Ctl.Name, Len(Ctl.Name) - InStr(Ctl.Name, "Chart")+1)

 
Posted : 23/08/2020 8:02 am
(@briantitus)
Posts: 8
Active Member
Topic starter
 

Hi Catalin

Still no joy.

what is the formula meant to do?

if the control name is tbtExitChart3Name.Value
what is the corrcet answer to this formula,

ChName = Right .... = 17 - 6 + 1 = 12

and when we replace stuff

ChName = Val ... = 0

 
Posted : 24/08/2020 1:52 am
(@catalinb)
Posts: 1937
Member Admin
 

Hi Brian,

Just for accuracy, the control name does not contain .Value, that is the method that extracts the value of that control.

This line:

Right("tbtExitChart3Name", Len("tbtExitChart3Name") - InStr("tbtExitChart3Name", "Chart")+1)

will return: "Chart3Name" , it's not meant to make math operations, it's doing text string manipulation.
It's very similar to this excel formula, you can try this in a cell: =RIGHT("tbtExitChart3Name", LEN("tbtExitChart3Name") - FIND("Chart","tbtExitChart3Name")+1)

The only difference is that in vba we use InStr instead of FIND.

Without being able to test it without images and folders you have, I think it returns the correct values now.

You can try with

ChName = R eplace(R eplace(ChName, "Chart", ""), "Name", "")

Please try to provide an error message, "still no joy" does not seem to be very descriptive 🙂

 
Posted : 24/08/2020 2:51 am
(@briantitus)
Posts: 8
Active Member
Topic starter
 

Hi Catalin

Thank you for that explanation.

Then I suppose the next line of code will remove the Chart and Name from Chart3Name to leave us with a nummber in this case 3.

Thing is when I run the code / initialise the form - I do not get an error message - the placeholder/ image for the picture is just blank. Please see the example attached.

Unless there is something else I should be meant to do?

Regards

Brian

 
Posted : 24/08/2020 4:00 am
(@catalinb)
Posts: 1937
Member Admin
 

Found my mistake, sorry:

If Ctl.Name Like "Chart*Name" Then
should be:
If Ctl.Name Like "*Chart*Name" Then

 
Posted : 25/08/2020 1:21 am
(@briantitus)
Posts: 8
Active Member
Topic starter
 

Hi Catalin

Thank you for getting back to me.

I made the changes in the private sub GetImage(). I went to run the macro and now it falls over at the first hurdle with a run time error 76. Path not found.

When I go to debug it takes me to the Sub ShowTradeJournalForm() and the only thing in there highligted in yellow is TradeJournalForm.Show

This Sub sits in the Modules section.

Pressing and holding F8 - just brings me back to this Sub. Any amendments you can suggest here?

Thanks in advance

Brian

 
Posted : 25/08/2020 3:58 am
(@catalinb)
Posts: 1937
Member Admin
 

Make sure the path used in your code is correct.

 
Posted : 25/08/2020 11:18 pm
Share: