Run Module HELP!!!

U

Utopian

Hello everbody.

I have a module (to create a Desktop ShortCut) that I expose below, and I need that it is executed when the Initial Form of my application loads

How to use this module????

I hope can help me, Thanks


--------------------------------------------------------------------------------



'*********************************************************
'
' CrearAccesoDirecto
'
' Rutina que crea un acceso directo en el escritorio de la
' base de datos actual. Si la bd tiene asociado un icono
' se utilizará para el acceso directo, y si no, se le
' pondrá el predeterminado para BDs de Access
'
' Autor: Juan M. Afán de Ribera
' Fecha: Junio 2003
'
Sub CrearAccesoDirecto()
Dim WScript As Object 'New WshShell
Dim AccesoDirecto As Object 'WshShortCut
Dim Escritorio As String

Set WScript = CreateObject("WScript.Shell")
'obtenemos la ruta del escritorio
Escritorio = WScript.SpecialFolders("Desktop")
'creamos el acceso directo a nuestra bd
Set AccesoDirecto = WScript.CreateShortcut _
(Escritorio & "\" & Dir(CurrentDb.Name) & ".lnk")
'decimos donde está la bd
AccesoDirecto.TargetPath = CurrentDb.Name

On Error GoTo err_IconoAccesoDirecto
AccesoDirecto.IconLocation = _
CurrentDb.Properties("AppIcon")

'indicamos el directorio de trabajo

'usuarios de Access 97 han de utilizar esta línea
'AccesoDirecto.WorkingDirectory = CurrentProjectPath

'usuarios de Access 2000 o superior han de utilizar
'esta línea
'AccesoDirecto.WorkingDirectory = CurrentProject.Path

'y grabamos el trabajo
AccesoDirecto.Save

exit_CrearAccesoDirecto:

Set AccesoDirecto = Nothing
Set WScript = Nothing
Exit Sub

err_IconoAccesoDirecto:

If Err.Number = 3270 Then 'no existe la propiedad
'asignamos el icono predeterminado para
'bases de datos de Access
AccesoDirecto.IconLocation = SysCmd( _
acSysCmdAccessDir) & "\msaccess.exe, 1"
Resume Next
Else
MsgBox Err.Description
GoTo exit_CrearAccesoDirecto
End If

End Sub
 
A

aaron.kempf

uh.. you can turn it into a function and then call it with a macro..
like the autoexec macro will run a bunch of steps for you

in a macro use runCode to point to you function
 
B

Brendan Reynolds

There is no need to convert the sub to a function in order to call it from a
form, just call the sub from the Open or Load event procedures of the form
....

Private Sub Form_Open(Cancel As Integer)

CrearAccesoDirecto

End Sub

If you wanted to use the procedure in one of the situations where you need a
function rather than a sub, you could change the sub to a function simply by
changing the word 'Sub' in the first line to 'Function'. Alternatively, you
could leave the sub alone and write a 'wrapper' function that simply called
the sub ...

Public Function WrapCrearAccesoDirecto ()
CrearAccesoDirecto
End Function

--
Brendan Reynolds (MVP)

How I can convert it to a Function???

Thanks.
 

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