Have not been following this post much, very busy. Anyway, in a nutshell what is the final outcome? and what does it do?
David
Dim cstrMSAccessAPP As String 'Folder path of Access Executable
cstrMSAccessAPP = SysCmd(acSysCmdAccessDir) & "MSAccess.exe"
Thanks for the update Wik.
So the command line token thing still works in 2007?
' If the expected folder structure on client machine does not exist, create it.
If Dir(cstrClientFEPath) = "" Then
MkDir (cstrClientFEPath)
End If
Cool -
I have to be carefull with token thing and a 'disable shift' that I always deploy a copy. I have locked myself completly out
When you have finished it would be nice if you could drop it into a sample mdb to test in different environments. You never know this may superseed BL's version.
David
and highlights my FileCopy line:Runtime error 75: Path/File access error
Option Compare Database
Private Sub cmdCopyShortcut_Click()
On Error GoTo Err_cmdCopyShortcut_Click
' SPECIAL FOLDERS -------------------------------------------------------
' http://www.rondebruin.nl/folder.htm
'
'FOR ALL USERS:
' AllUsersDesktop, AllUsersStartMenu, AllUsersPrograms, AllUsersStartup
'
'FOR CURRENT USER:
' Desktop, Favorites, Fonts, MyDocuments, NetHood, PrintHood, Programs,
' Recent, SendTo, StartMenu, Startup, Templates
' -----------------------------------------------------------------------
'Get Special folder
Dim objWshShell As Object
Dim strSpecialPath As String
Dim strCopyPath As String
Set objWshShell = CreateObject("WScript.Shell")
strSpecialPath = objWshShell.SpecialFolders("AllUsersDesktop")
strCopyPath = "C:\Users\Agnieszka\Documents\Database Work\RLS Orders.lnk"
FileCopy strCopyPath, strSpecialPath
'MsgBox strSpecialPath
'Open folder in Explorer
'Shell "explorer.exe " & strSpecialPath, vbNormalFocus
Exit_cmdCopyShortcut_Click:
Exit Sub
Err_cmdCopyShortcut_Click:
Msg = "Error # " & Str(Err.Number) & Chr(13) & " (" & Err.Description & ")"
Msg = Msg & Chr(13) & "in Form_frmSpecialFolders | cmdCopyShortcut_Click"
MsgBox Msg, vbOKOnly, "Database1", Err.HelpFile, Err.HelpContext
Resume Exit_cmdCopyShortcut_Click
End Sub
Just a thought about copying *.lnk files. When ever I have to remotely roll out *.lnk files with a script, I notice that the *.lnk file will not copy for some reason. So what I usually do is change the extension of the file to *.txt and then copy it and once copied I rename it to a *.lnk file and it always works that way.
So I wonder if this is somewhat similar. just my .02 cents.
René
it's not a shortcut extension problem, i don't think, b/c i tried copying a regular xlsx file and it didn't like that either.
Sorry to have confused you. When I re-read your comment and found the following quoted text:
I realized I may have just reiterated what you had already stated. So I deleted the post right away thiking that maybe noone had seen it already...notthinking that you would have received an email instantly.
René
Option Compare Database
Option Explicit
Function CreateDatabaseShortcut(Optional Location = "Desktop")
On Error GoTo CreateDatabaseShortcut_error
'Makes a shortcut to this database file in Location
'Location options are "Desktop","AllUsersDesktop","Favorites","StartMenu","AllUsersStartMenu","Startup","AllUsersStartup"
Dim shell, Path, link, Msg, r
Select Case Location
Case "Desktop"
Msg = "Create a shortcut to the database on your desktop?"
Case "AllUsersDesktop"
Msg = "Create a shortcut to the database on the desktop for all users of this machine?"
Case "Favorites"
Msg = "Create a shortcut to the database in your list of favourites?"
Case "StartMenu"
Msg = "Create a shortcut to the database in your Start All Programs Menu?"
Case "AllUsersStartMenu"
Msg = "Create a shortcut to the database on the Start All Programs Menu for all users of this machine?"
Case "Startup"
Msg = "Create a shortcut to the database in your Startup folder?"
Msg = Msg & vbNewLine & "The database will open automatically every time you start this machine."
Case "AllUsersStartup"
Msg = "Create a shortcut to the database in the Startup folder for all users of this machine?"
Msg = Msg & vbNewLine & "The database will open automatically every time this machine is started."
Case Else
MsgBox "Not a valid shortcut to the database location: " & Location, vbExclamation + vbOKOnly, "Error in CreateDatabaseshortcut to the database"
GoTo CreateDatabaseShortcut_Exit
End Select
r = MsgBox(Msg, vbQuestion + vbYesNo, "Confirm")
If r = vbNo Then GoTo CreateDatabaseShortcut_Exit
Set shell = CreateObject("WScript.shell")
Path = shell.SpecialFolders(Location)
Set link = shell.CreateShortcut(Path & "\" & DMin("[ApplicationFullTitle]", "[[COLOR="Red"]tblSystemCode[/COLOR]]") & ".lnk")
link.Description = DMin("[ApplicationFullTitle]", "[[COLOR="red"]tblSystemCode[/COLOR]]") & vbNewLine & [COLOR="red"]"from www.YourWebAddressHere(Optional)"[/COLOR]
link.TargetPath = GetCurrentDBpath
link.WindowStyle = 3
link.WorkingDirectory = GetCurrentDBpath(False, False)
link.Save
Msg = Replace(Msg, "Create a Shortcut to the database", "A shortcut to the database has been created")
Msg = Replace(Msg, "?", ".")
MsgBox Msg, vbOKOnly + vbInformation, "Shortcut Created"
CreateDatabaseShortcut_Exit:
On Error Resume Next
Set shell = Nothing
Exit Function
CreateDatabaseShortcut_error:
Select Case Err
Case Else
MsgBox Err & "-" & Error$, vbCritical + vbOKOnly, "Error in module CreateDatabaseShortcut"
Resume CreateDatabaseShortcut_Exit
End Select
End Function
Function MakeShortcut()
On Error GoTo MakeShortcut_error
Dim s As String
Dim r As Long
Dim Rs As Recordset
[COLOR="red"] Set Rs = CurrentDb.OpenRecordset("SELECT * FROM [Tbl-Users] WHERE UserID = """ & GetUserID() & """", dbOpenDynaset)[/COLOR]
If Not Nz(Rs![UserShortcut], False) Then
s = "Would you like me to create a shortcut to this database on"
s = s & vbNewLine
s = s & "your desktop so that you can find it again later?"
r = MsgBox(s, vbYesNo + vbQuestion, "Make Shortcut?")
If r = vbYes Then
CreateDatabaseShortcut
End If
Rs.Edit
Rs![UserShortcut] = True
Rs.Update
End If
MakeShortcut_Exit:
On Error Resume Next
Rs.Close
Set Rs = Nothing
Exit Function
MakeShortcut_error:
Select Case Err
Case Else
MsgBox Err & "-" & Error$, vbCritical + vbOKOnly, "Error in module MakeShortcut"
Resume MakeShortcut_Exit
End Select
End Function
Wik,
Here is a module that asks the user if they want to create a shortcut on theor machine if it not present. This might work for you.
'1;"All Users - Desktop";"AllUsersDesktop";
'2;"All Users - Start Menu";"AllUsersStartMenu";
'3;"All Users - Startup *";"AllUsersStartup";
'4;"Single User - Desktop";"Desktop";
'5;"Single User - Start Menu";"StartMenu";
'6;"Single User - Startup *";"Startup";
'7;"Single User - My Documents";"MyDocuments"
Private Sub Form_Open(Cancel As Integer)
On Error GoTo Err_Form_Open
' VB Project Name can be set by code using
' Application.VBE.VBProjects("VBAProject").Name = NewName
' OR
' via Tools | <projectname> Properties... in VB Editor (VBE)
' get the VBE project name and use it as the ShortcutName
Me.txtShortcutName.Value = Application.VBE.ActiveVBProject.Name
Exit_Form_Open:
Exit Sub
Err_Form_Open:
Msg = "Error # " & Str(Err.Number) & Chr(13) & " (" & Err.Description & ")"
Msg = Msg & Chr(13) & "in Form_frmSettings | Form_Open"
MsgBox Msg, vbMsgBoxHelpButton, "RLS Orders", Err.HelpFile, Err.HelpContext
Resume Exit_Form_Open
End Sub
Private Sub cmdShortcutCreate_Click()
On Error GoTo Err_cmdShortcutCreate_Click
Dim objShell As Object
Dim strPath As String
Dim strTargetPath As String
Dim strTarget As String
Dim Msg As String
Dim link
Select Case Me.cmbShortcutLocation.Column(0)
Case 1, 2, 3, 4, 5, 6, 7 'valid selections, continue with code
Case Else 'invalid selection, get user to chose from combo
MsgBox "Invalid Shortcut Location." & Chr(13) _
& "Please select a location from the dropdown.", _
vbExclamation + vbOKOnly, "RLS Orders Error"
Me.cmbShortcutLocation.SetFocus
GoTo Exit_cmdShortcutCreate_Click
End Select
strTargetPath = fHTC_GetBEFolder("tblOrders")
strTargetFile = strTargetPath & "\ORDERS_ReferenceLabs.mdb"
Set objShell = CreateObject("WScript.shell")
strPath = objShell.SpecialFolders(Me.cmbShortcutLocation.Column(2))
'--------------------------------------------------------------------------------
' shortcut creation code adapted from DCrake (AWF)
' http://www.access-programmers.co.uk/forums/
Set link = objShell.CreateShortcut(strPath & "\" & Me.txtShortcutName & ".lnk")
link.Description = "Record and track orders for Reference Section Labs"
link.TargetPath = strTargetFile
link.WindowStyle = 3
link.WorkingDirectory = strTargetPath
link.HotKey = "CTRL+SHIFT+O" '"O" for "Orders"
link.Save
'--------------------------------------------------------------------------------
MsgBox "Shortchut created successfully for:" & Chr(13) & Chr(13) _
& Me.cmbShortcutLocation.Column(1) & Chr(13) & Chr(13) _
& "(" & strPath & ")", vbInformation + vbOKOnly, "RLS Orders"
Exit_cmdShortcutCreate_Click:
Exit Sub
Err_cmdShortcutCreate_Click:
Msg = "Error # " & Str(Err.Number) & Chr(13) & " (" & Err.Description & ")"
Msg = Msg & Chr(13) & "in Form_frmSettings | cmdCreateShortcut_Click"
MsgBox Msg, vbMsgBoxHelpButton, "RLS Orders", Err.HelpFile, Err.HelpContext
Resume Exit_cmdShortcutCreate_Click
End Sub
Private Sub cmdShortcutRemove_Click()
On Error GoTo Err_cmdShortcutRemove_Click
Dim objShell As Object
Dim strPath As String
Dim Msg As String
Select Case Me.cmbShortcutLocation.Column(0)
Case 1, 2, 3, 4, 5, 6, 7 'valid selections, continue with code
Case Else 'invalid selection, get user to chose from combo
MsgBox "Invalid Shortcut Location." & Chr(13) _
& "Please select a location from the dropdown.", _
vbExclamation + vbOKOnly, "RLS Orders Error"
Me.cmbShortcutLocation.SetFocus
GoTo Exit_cmdShortcutRemove_Click
End Select
Set objShell = CreateObject("WScript.shell")
strPath = objShell.SpecialFolders(Me.cmbShortcutLocation.Column(2)) & "\" & Me.txtShortcutName & ".lnk"
Kill strPath
MsgBox "Shortcut removed for: " & Chr(13) & Chr(13) _
& Me.cmbShortcutLocation.Column(1), _
vbInformation + vbOKOnly, "RLS Orders"
Exit_cmdShortcutRemove_Click:
Exit Sub
Err_cmdShortcutRemove_Click:
Msg = "Error # " & Str(Err.Number) & Chr(13) & " (" & Err.Description & ")"
Msg = Msg & Chr(13) & "in Form_frmSettings | cmdShortcutRemove_Click"
MsgBox Msg, vbMsgBoxHelpButton, "RLS Orders", Err.HelpFile, Err.HelpContext
Resume Exit_cmdShortcutRemove_Click
End Sub