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
 
J

JimBurke via AccessMonster.com

What do you mean by a shortcut? Not really sure exactly what it is you need
to accomplish. Do you just want to open a form in VBA? Use a button to open a
form? Need more info.
 
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
 
J

JimBurke via AccessMonster.com

I didn't know you could do that. Here's a page with the Microsoft explanation
of how to use that - it looks OK to me from what I can see. Maybe someone
else here has used this before and knows.

http://support.microsoft.com/kb/209207
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
What do you mean by a shortcut? Not really sure exactly what it is you need
to accomplish. Do you just want to open a form in VBA? Use a button to open a
[quoted text clipped - 5 lines]
 
C

Chris O'C via AccessMonster.com

Yes. The syntax requires a complete os command like you'd type from the os
shell. A complete command requires and executable file name (.exe, .cmd, .
bat, etc) and zero or more arguments.

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.

If your shortcut used the following syntax (on one line), it'd work:

"c:\program files\microsoft office\office11\msaccess.exe" "D:\Main\My
Documents\devlor.mdb" /x PerfChecks

Chris
 
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
 
C

Chris O'C via AccessMonster.com

Check the registry. If there's only 1 version of Access installed, check the
path in this key:

HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Applications\MSACCESS.EXE\shell\Open\
command

If there's more than one version installed, get the current version with this
key:

HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Access.Application\CurVer

It will be a string like this, depending on the version: Access.Application.
11

Use that to find the key for the path:

HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Access.Application.11\shell\Open\command

It doesn't matter if it's the runtime version. The file name is the same.

Chris
 
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.
 
C

Chris O'C via AccessMonster.com

The code you posted doesn't quite make the target you posted, but it's close.
The "C:\"C:\Program Files\..." part is correct (though not what you wanted).
The target your code makes doesn't have a space between the path to the
executable string and the file path to the mdb. It doesn't have a forward
slash either.

The reason you're getting the extra "C:\" at the beginning is because you
preceded the string with Chr(34). Remove that concatenation and you'll get
rid of the extra "C:\".

That won't fix the other problems, namely the parameter after the file name,
especially since it contains a slash character, which Windows reverses to a
backslash when it creates the shortcut. You need special syntax. I've seen
an example on one of the MVP's sites. I thought I had it bookmarked but I
guess not. I'll find it and post back later with the link.

Chris
 
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
 
C

Chris O'C via AccessMonster.com

I told you you need special syntax. :) I found the example on Tom
Wickerath's site.

http://www.access.qbuilt.com/html/vba3.html

In createDBShortcut(), change

sDBPath = "D:\MyDB.mdb"
sParams = " /runtime"

to this

sDBPath = "D:\Tasks.mdb"
sParams = " /x Macro1"

See if that works for you. It'll put the shortcut on your desktop.

Chris
 
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
 

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