The easiest way to create a shortcut to your MS Access Form is to open your database and select 'Tools', then
'Startup'. Once there, select from the drop down named "Display/Form Page' the Form that you would like to display whenever your database is opened. Once you have defined the form to open, you can make that form look like a menu by using command buttons and by removing scroll bars etc.
However to dynamically open the database with different views for different operators on different machines, we hope this lesson will get you started in the direction of a more customizable approach of for example using the
appropriate menu for different users and classes of users.
Here's a synopsis of how this works. The desktop shortcut contains a path to your ms access program, your database, and the form you want to open. A new macro that you create called 'AutoExec' says 'Run a function in my Module' and that Macro is always automatically run whenever Ms Access starts up and that's why it's called 'AutoExec'. Also, you will create that function in a new module and when run, it looks at the 'Command' that was passed in by the caller (shortcut) and based on what it is, runs the appropriate form. With a little experimenting, you also may be able to run queries, reports and other database commands.
Public Function CheckCommandLine() As Boolean
CheckCommandLine = True
If Len(Trim(Command)) = 0 Then Exit Function' this is a regular open
Dim iPos As Integer
Dim sMyCommand As String
iPos = InStr(Command, "=")
sMyCommand = Trim(Mid(Command, iPos + 1))
sMyCommand = Mid(sMyCommand, 2)
iPos = Len(sMyCommand)
If iPos < 0 Then iPos = 1
sMyCommand = Mid(sMyCommand, 1, iPos - 1)
Select Case sMyCommand
Case "EMPLOYEE_FORM"
DoCmd.OpenForm "Employee_Form"
Case "OPEN_FOR_ANYCOMMAND"
DoCmd.OpenForm "Employee_Form"
Case "MORE_OPEN_FOR_ANYCOMMAND"
DoCmd.OpenForm "Employee_Form"
End Select
End Function
Note that we have left a few other places open in the function where you can add other forms.
Action: RunCode
Function Name: CheckCommandLine()
This step requires that after you select 'Runcode' from the drop down that you click in the 'function name:'
textbox to bring up the prompts to browse to the function that you entered in step 1. If you're feeling
lucky, just type into the box: CheckCommandLine ()
However, remember that technically you should browse down to it to make sure it is there. Here is how you would do the
browse:
1.) click on the three dots '...' along side the function textbox
2.) when a new form appears, double click 'function'
3.) two nodes will appear, double click the one that is the name of your database
4.) click the 'module_our_command_parser'
5.) double click 'CheckCommandLine' This 'CheckCommandLine' will appear in the upper top box.
6.) That's it, click 'OK' and when you exit, you will be prompted for the name. Enter 'AutoExec'
Note that some of us remember the old dos days when the autoexec.bat was automatically run at boot time.
Before you create the desktop shortcut, you can test things out by using your desktop 'Start' > 'Run' functions.
Do the Start > Run and in the Run text box enter the same thing that can be entered into the shortcut path, something we call the long-path-command that looks something like this:
"C:\Program Files\Microsoft Office\Office\Msaccess.exe" "C:\Familia\Personnel.mdb" /cmd = "Employee_Form"
Note that the first quoted section is the path to your machines 'MS Access Program'.
This may vary especially if you are running Windows 2000.
Note that the second quoted section is the path to your database and includes the .mdb extension.
Note that the third section starts un-quoted with the 'forward slash', 'cmd', 'equal sign' like this:
/cmd =
followed by the quoted name of the MS Access form or command that you want to run when you click on the desktop shortcut.
Once you have experimented using the run command and have successfully opened the form using the run command, it's the right time to take a walk on the wild side and create your desktop shortcut.
When you're ready, start by right mouse clicking on a free area of the desktop.
Select 'New' > 'Shortcut'
Then just paste the long-path-command that you used while experimenting with the Run command into the Browse Textbox. Now click 'Next' until you get to the part where it will prompt for the shortcut name. For that, enter what you want, something like '[mydatabase] [myform]'
Modify the long-path-command to suit the path where MS Access resides on your machine
Modify the long-path-command to suit the path to your database
Modify the long-path-command to suit the form that you want to run
Modify the 'CheckcommandLine() function line: Case "EMPLOYEE_FORM" (changing 'EMPLOYEE_FORM' to the name of the form you will be passing in the long-path-command)
Modify the 'CheckcommandLine() function line: DoCmd.OpenForm "Employee_Form" (changing 'Employee_Form' to your form name)
Note that we have left a few other places open in the function where you can add other forms.
| Problem | Solution |
|---|---|
| Shortcut gives Error message that the command is wrong | Make sure you used a forward slash '/' in the long-path-command |
| Database opens but the form doesn't load | Open the database, open Macro tab, Insure that double clicking on the autoexec macro, opens the form. Also insure that the long-path-command contains a form that exists |
| shortcut doesn't run Ms Access | Check the path in the shortcut to MS Access. Paste it into the Start > Run and insure it runs it from there |
| Everything seems to work but the form doesn't load | Place code in the Module like this: msgbox "Here". If the module function is getting called, the message box will appear. If not, the Macro is not calling the Module Function. To fix, redo the Macro 'AutoExec' to make sure it calls 'CheckCommandLine()' |