I am trying to automatically open a word document in a folder based on the criteria of a field on the form. I Can get it working so i can get to the folder and then double click to open the file but how can i get the file to open just by clicking the button preferably in read only mode.
Here is my code:
Private Sub Command56_Click()
Const Prep = "\\sbserver\dart$\Document-Library\Doc-Production"
'Const Pub = "\\Servername\DART$\Document-Library\Public"
'Const Res = "\\Servername\DART$\Document-Library\Restricted"
'Const Conf = "\\Servername\DART$\Document-Library\Confidential"
'Const HR = "\\Servername\DART$\Document-Library\HR"
'Const Secure = "\\Servername\DART$\Document-Library\Secure"
'Dim OldPath As String
'Dim NewPath As String
'Dim LoopFile As String
'Dim FileExt() As String
'Dim Doc_Folder As String
'Dim Folder As String
'Dim fso As Object
' Get Main ID from control
'Doc_Folder = Me.Doc_Folder
'Hyperlink = Me.Hyperlink
' OldPath = (Prep)
'NewPath = Replace(Pub & Doc_Number & "", "/", "-")
'LoopFile = Dir(OldPath & "*.*")
'Do While LoopFile <> ""
'FileExt = Split(LoopFile, ".")
'Select Case FileExt(UBound(FileExt))
'Case "docx", "doc"
'Name OldPath & LoopFile As NewPath & LoopFile
' End Select
'LoopFile = Dir
'Loop
'If Document_Classification = "Classified" Then
'Folder = Replace(Conf & Doc_Number, "/", "-")
'Else
'Internal_Document_Library = "No" And Website_Document_Library = "Yes" Then
Folder = Replace(Prep & Doc_Number, "/", "-")
'End If
' Create FileSystemObject
Set fso = CreateObject("Scripting.FileSystemObject")
' Check whether folder exists
If fso.FolderExists(Folder) = False Then
' If not, create it
fso.CreateFolder Folder
End If
' Open it
Shell "explorer.exe " & Folder, vbNormalFocus
End Sub
Here is my code:
Private Sub Command56_Click()
Const Prep = "\\sbserver\dart$\Document-Library\Doc-Production"
'Const Pub = "\\Servername\DART$\Document-Library\Public"
'Const Res = "\\Servername\DART$\Document-Library\Restricted"
'Const Conf = "\\Servername\DART$\Document-Library\Confidential"
'Const HR = "\\Servername\DART$\Document-Library\HR"
'Const Secure = "\\Servername\DART$\Document-Library\Secure"
'Dim OldPath As String
'Dim NewPath As String
'Dim LoopFile As String
'Dim FileExt() As String
'Dim Doc_Folder As String
'Dim Folder As String
'Dim fso As Object
' Get Main ID from control
'Doc_Folder = Me.Doc_Folder
'Hyperlink = Me.Hyperlink
' OldPath = (Prep)
'NewPath = Replace(Pub & Doc_Number & "", "/", "-")
'LoopFile = Dir(OldPath & "*.*")
'Do While LoopFile <> ""
'FileExt = Split(LoopFile, ".")
'Select Case FileExt(UBound(FileExt))
'Case "docx", "doc"
'Name OldPath & LoopFile As NewPath & LoopFile
' End Select
'LoopFile = Dir
'Loop
'If Document_Classification = "Classified" Then
'Folder = Replace(Conf & Doc_Number, "/", "-")
'Else
'Internal_Document_Library = "No" And Website_Document_Library = "Yes" Then
Folder = Replace(Prep & Doc_Number, "/", "-")
'End If
' Create FileSystemObject
Set fso = CreateObject("Scripting.FileSystemObject")
' Check whether folder exists
If fso.FolderExists(Folder) = False Then
' If not, create it
fso.CreateFolder Folder
End If
' Open it
Shell "explorer.exe " & Folder, vbNormalFocus
End Sub