Button to go to desktop from form (1 Viewer)

BBBryan

Registered User.
Local time
Yesterday, 18:17
Joined
Nov 13, 2010
Messages
122
Hi All,
I was trying from a button on my form that will go to and bring up the desktop. I want it so I can put this database on anyone's computer and the button will work.
I am using this and it works but only on my computer.
Application.FollowHyperlink "C:\Users\Bryan\Desktop\"

I also tried this
Application.FollowHyperlink "C:\Show Desktop.scf"
And
Application.FollowHyperlink "C:\WINDOWS\System\Show Desktop.scf"
Both gives Runtime error 490 cannot open specified file.

Thanks BBryan
 

Encarta

New member
Local time
Today, 01:17
Joined
Mar 23, 2013
Messages
5
Try putting this code behind the button. Supposing the name of the button is cmdShowDesktop, then the code will be:

Private Sub cmdShowDesktop_Click()
Application.DoCmd.Minimise
End Sub

Thank you.
 

Ari

Registered User.
Local time
Yesterday, 17:17
Joined
Oct 22, 2011
Messages
139
Or

Application.FollowHyperlink "C:\Users\" & environ("UserName") & \Desktop\"
 

BBBryan

Registered User.
Local time
Yesterday, 18:17
Joined
Nov 13, 2010
Messages
122
Thanks for the help.
On this one I get an error method or member not found
Application.DoCmd.Minimise
It is blue on the .Minimise

Also on this one
Application.FollowHyperlink "C:\Users\" & environ("UserName") & \Desktop\"
I get an compile error syntax error
and it shows the whole line in blue

Not sure how to fix this. I
Thanks BBryan
 

Gasman

Enthusiastic Amateur
Local time
Today, 01:17
Joined
Sep 21, 2011
Messages
14,299
Probably should be

Application.FollowHyperlink "C:\Users\" & environ("UserName") & "\Desktop\"

as there are three separate strings to be combined
 

namliam

The Mailman - AWF VIP
Local time
Today, 02:17
Joined
Aug 11, 2003
Messages
11,695
Try this :)
CreateObject("Shell.Application").MinimizeAll
 

BBBryan

Registered User.
Local time
Yesterday, 18:17
Joined
Nov 13, 2010
Messages
122
Hi All, Thanks
this one again I get an run time error 490 cannot open specified file
Application.FollowHyperlink "C:\Users\" & environ("UserName") & "\Desktop\"

This one works
CreateObject("Shell.Application").MinimizeAll
But I really wanted to keep the database open and bring up the desktop Box on top of the open database just like it does with this one
Application.FollowHyperlink "C:\Users\Bryan\Desktop\"

Thanks BBryan
 

Encarta

New member
Local time
Today, 01:17
Joined
Mar 23, 2013
Messages
5
I beleive that the "Application.Minimize" is the ideal solution. What if you are running the Database on a Computer whose user is not "Bryan"? The "Bryan" element in the code string will give errors.

So try the: Application.Minimize
 

BBBryan

Registered User.
Local time
Yesterday, 18:17
Joined
Nov 13, 2010
Messages
122
Hi Encarta,
Thanks
I am using that one but it would still not be my first choice. If there was something like " & environ("UserName") & " that could retrieve the computor name that would work better for me. (And the " & environ("UserName") & " gave me an error see above). I want it so it is a pop-up window not minimize the database which this is doing.


Thanks BBryan
 

namliam

The Mailman - AWF VIP
Local time
Today, 02:17
Joined
Aug 11, 2003
Messages
11,695
Cant you find the desktop in one of the environ settings?
Code:
        Dim i As Integer
        i = 1
         
        While Environ(i) <> Empty
             
            Debug.Print Environ(i)
             
            i = i + 1
             
        Wend

Or try running the explorer directly with something like:
Code:
shell("explorer.exe C:\Users\" & environ("UserName") & "\Desktop")
Just throwin idea's
 

BBBryan

Registered User.
Local time
Yesterday, 18:17
Joined
Nov 13, 2010
Messages
122
Thanks All,
Sorry
I still can't get the desktop to pop-up.
This one shell("explorer.exe C:\Users\" & environ("UserName") & "\Desktop") put the documents Folder minimized on the task bar.

Not sure how to use the other code you sent... from my button.


Thanks BBryan
 

namliam

The Mailman - AWF VIP
Local time
Today, 02:17
Joined
Aug 11, 2003
Messages
11,695
Just stick the code in a sub and run it... should display all the environ values in the debug window (press CTRL + T to bring it up)

Try looking up shell on the help, google is your friend :)
Minimized is the default, you can easily add vbNormalFocus to make it stick on top
Code:
shell("explorer.exe C:\Users\" & environ("UserName") & "\Desktop", vbNormalFocus)
 

BBBryan

Registered User.
Local time
Yesterday, 18:17
Joined
Nov 13, 2010
Messages
122
Thanks Namliam,
I will read up on shell. I am not to familiar with it. It looks like it could be useful for me.


BBryan
 

Gasman

Enthusiastic Amateur
Local time
Today, 01:17
Joined
Sep 21, 2011
Messages
14,299
I just created a form with one button with the code below for the click event

Application.FollowHyperlink "C:\Users\" & Environ("UserName") & "\Desktop\"

and it works fine, in that it opens an explorer window to the folder.?

It does the same if I hard code my user name.

Open a command window and type in 'set' without the quotes

That will show all the variables in the system. One should be USERNAME, but the variables are not case sensitive.

HTH
 

BBBryan

Registered User.
Local time
Yesterday, 18:17
Joined
Nov 13, 2010
Messages
122
Hi Gasman,
Thanks
I just tried it again. Still doesn't work.
I am on windows 8.1 if that matters.


Thanks BBryan
 

Gasman

Enthusiastic Amateur
Local time
Today, 01:17
Joined
Sep 21, 2011
Messages
14,299
I'm only on win 7 and Access 2003, but that is very strange.:banghead:

I am presuming you copied the code and pasted.?, that is what I did.

Did you check the variables with the cmd window?, though I cannot see username not being available?
 

BBBryan

Registered User.
Local time
Yesterday, 18:17
Joined
Nov 13, 2010
Messages
122
Yes I copied and pasted it and I do see username.
Not sure why it is not working....

After looking on the internet for something else I just found this.
And It works.....
Application.FollowHyperlink Environ$("UserProfile") & "\Desktop\"

Thanks All for your help. (I will need it again)

Thanks BBryan
 

Gasman

Enthusiastic Amateur
Local time
Today, 01:17
Joined
Sep 21, 2011
Messages
14,299
I was going to suggest userprofile as that is more useful, as if you had xp, it would be c:\documents & settings\<username>, totally different from Vista, 7 & 8, but thought if one varialble would not work, another should not be any different.

What is different is the $ sign on the environ function.

I'd try that with the username variable and the original string and see if that works.?

The difference is asked here http://www.excelforum.com/excel-pro...en-environ-username-and-environ-username.html, but not answered.

Please do me a favour and try environ$ with username. I'd like to know what the result is. :)

I've just tested environ$ with username in my Access and O/S and it works as the other code did. Perhaps that is now an win 8 requiremnt? It would be good to find out. ;-)
 
Last edited:

BBBryan

Registered User.
Local time
Yesterday, 18:17
Joined
Nov 13, 2010
Messages
122
I tried this
Application.FollowHyperlink Environ$("BBryan") & "\Desktop\"
And This
Application.FollowHyperlink Environ$(BBryan) & "\Desktop\"

And it didn't work...

Thanks BBryan
 

Users who are viewing this thread

Top Bottom