Shortcut to a form

Q

QB

I know one can create a shortcut to a form, but how can I do this using vba?

Thank you for your help,

QB
 
Q

QB

Jim,

actually my question has changed since I posted it originally. I am now
able to create a shortcut using vba to launch my db.

My issue is that I want the shortcut to run a macro. I tried using the /x
command line switch but it does nothing. The db opens correctly, but nothing
happens! I checked the macro does work.

My shortcut's target is
"D:\Main\My Documents\devlor.mdb" /x PerfChecks

Any idea why it will not trigger the macro. Is my synthax wrong?

Thank you,

QB
 
D

dymondjack

Try extending the quote to include the /x switch as well?
--
Jack Leach
www.tristatemachine.com

- "Success is the ability to go from one failure to another with no loss of
enthusiasm." - Sir Winston Churchill
 
D

dymondjack

Maybe the switch is only valid when shelling the actual exectutable:

"""C:\...\OFFICE11\ACCESS11.EXE"" ""C:\Your Folder\asdf.mdb"" /x PerfChecks"


--
Jack Leach
www.tristatemachine.com

- "Success is the ability to go from one failure to another with no loss of
enthusiasm." - Sir Winston Churchill
 
J

John W. Vinson

Jim,

actually my question has changed since I posted it originally. I am now
able to create a shortcut using vba to launch my db.

My issue is that I want the shortcut to run a macro. I tried using the /x
command line switch but it does nothing. The db opens correctly, but nothing
happens! I checked the macro does work.

My shortcut's target is
"D:\Main\My Documents\devlor.mdb" /x PerfChecks

Any idea why it will not trigger the macro. Is my synthax wrong?

When I've used a shortcut to open a database with a macro switch, I've
included the Access executable: e.g. the shortcut target

"C:\Program Files\yaddayadda\msaccess.exe" "D:\Main\My Documents\devlor.mdb"
/x PerfChecks

all on one line of course.
 
Q

QB

Right on the money, it works! Now why couldn't they indicate that somewhere
that in shortcuts it require listing the exe....?

Thank you!

QB
 
Q

QB

Your answer now raises another question.

I am creating the shortcut using automation. How do I determine the exe
string for the user's pc?

"c:\program files\microsoft office\office11\msaccess.exe"

what about run-time, does this impact the shortcut?

Thank you,

QB
 
Q

QB

Chris,

I managed to grab the exe but now creating the shortcut fails. I shouldn't
say fails, because it does create a shortcut but the target is wrong.

Set oWsh = CreateObject("WScript.Shell")
szShortcutPath = oWsh.SpecialFolders(szlocation)

' Create the shortcut path/filename
szShortcut = "D:\Main\My Documents\"

' Create the Shortcut target
' For my purposes I need to include the exe to run the db
szTarget = Chr(34) & "C:\Program Files\Microsoft
Office\OFFICE11\MSACCESS.EXE" & _
Chr(34) & "D:\Tasks.mdb" & Chr(34) & " /x Macro1"

' Create the Shortcut file
Set oShortcut = oWsh.CreateShortCut(szShortcut)

' Populate the Shortcut properties
With oShortcut
.TargetPath = szTarget
.Save
End With

' Cleanup our object variables
Set oShortcut = Nothing
Set oWsh = Nothing


When i run this and check my variables the szTarget is correct

"C:\Program Files\Microsoft Office\OFFICE11\MSACCESS.EXE" "D:\Tasks.mdb" /x
Macro1

but the target in the link is

"C:\"C:\Program Files\Microsoft Office\OFFICE11\MSACCESS.EXE" "D:\Tasks.mdb"
/x Macro1"

Do you know why this is happening? or how I can fix it?

Thank you for all your help

QB
 
J

John W. Vinson

The result of not supplying a complete os command is the os will look in the
registry for the executable associated with the file name and associated
arguments. These are called the defaults. Your defaults (till you change
them) look something like this:

"c:\program files\microsoft office\office11\msaccess.exe" %1

That means no matter how many arguments you supplied, it only accepts one
argument, the file name, and ignores the rest.

ahhhhhhh....

Thanks, Chris. I knew about the phenomenon (and still remember some of the old
DOS 3.11 command line syntax) but had never seen this excellent explanation of
why it works that way.
 
Q

QB

Your previous post allowed me to figure it out.

I added the /x Macro1 to the argument of the Shortcut

..Arguments = "/x Macro1"

everthing seems in order (for now :) ).

Thank you once again.

Qb
 
Q

QB

I spoke to soon!

When i open the shortcut properties, it is correct and yet when I launch the
shortcut I get a Locate the File prompt.

If I edit the target add cut the argument, close it, reopen it and paste
back the argument (not making any changes whatsoever) and then lanuch it it
work?!?!?!?!?

I am baffled and lost (again).

QB
 
Q

QB

I spoke too soon!

The routine (see below) does indeed create a shortcut with the proper
synthax. But when I try to launch it, it does not work and I get a Missing
Shortcut dialog asking me to locate the file.....

Yet, If I open the shortcut properties, cut the argument from the end, apply
the change then paste back the argument and close the shortcut and launch it
it works. What the?!?!

Function CreateDesktopShortcut() As Boolean
On Error GoTo Error_Handler
'Special folder location where the shortcut will be created
Const szlocation As String = "Startup"
'Extension that will be used for the shortcut file
Const szLinkExt As String = ".lnk"

Dim oWsh As Object 'WScript object
Dim oShortcut As Object 'Shortcut object
Dim szDb As String 'Path\Name.Ext of the current database
Dim szShortcutPath As String 'Path where to create the shortcut
Dim szShortcutName As String 'Name to be given to the shortcut
Dim szShortcut As String
Dim szTarget As String

' Initialize our variables
szDb = Application.CurrentDb.name
szShortcutName = "ReminderDb"

Set oWsh = CreateObject("WScript.Shell")
szShortcutPath = oWsh.SpecialFolders(szlocation)

' Create the shortcut path/filename
szShortcut = szShortcutPath & "\" & szShortcutName & szLinkExt

' Create the Shortcut target
' For my purposes I need to include the exe to run the db
szTarget = GetFileExecutable(Application.CurrentProject.name, _
Application.CurrentProject.Path) & Chr(34) & " "
szTarget = szTarget & Chr(34) & szDb

' Create the Shortcut file
Set oShortcut = oWsh.CreateShortCut(szShortcut)

' Populate the Shortcut properties
With oShortcut
.TargetPath = szTarget
' .IconLocation = szPath & szIconName
' .WorkingDirectory = WorkPath
' .WindowStyle = Window_Style
.Arguments = " /cmd = 'checkrem'"
'/cmd = "checkrem"
' .Hotkey
.Description = "Database date check routine"
' .IconLocation = TargetPath & "," & IconNum
.Save
End With

' Cleanup our object variables
Set oShortcut = Nothing
Set oWsh = Nothing

' if I've made it to here, everything is fine.
CreateDesktopShortcut = True

If Err.Number = 0 Then Exit Function

Error_Handler:
CreateDesktopShortcut = False
MsgBox "MS Access has generated the following error" & vbCrLf & vbCrLf &
"Error Number: " & _
Err.Number & vbCrLf & "Error Source: CreateDesktopShortcut" & vbCrLf &
"Error Description: " & _
Err.Description, vbCritical, "An Error has Occured!"
Exit Function
End Function

If you see something in my code that is blazingly wrong or explains this
weird behavior, please let me know.

So close, but so far!

QB
 
Q

QB

Chris disregard my previous/next post I hadn't seen my original post or your
reply.

Anyways. It didn't solve my problem directly, but the link allowed me to
learn from his example and resolve my issue.

Who knew the exe was the target and the db with the cmd line switch was the
argument?! Because I was including the db with the exe as the target, it
wouldn't work.

I can't believe something this simple took me this long to get to work.

Thank you for sticking with me on this one!

QB
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top