Option Compare Database Function Openword(conPath As String) Dim appword As Word.Application Dim doc As Word.Document On Error Resume Next Error.Clear Set appword = GetObject(, "word.application") If Err.Number <> 0 Then Set appword = New Word.Application appword.Visible = True End If Set doc = appword.Documents.Open(conPath, , True) appword.Activate Set doc = Nothing Set appword = Nothing End Function Private Sub Command5_Click() Dim mydoc As String mydoc = "J:\3 - Client Services\Nestle\1-Programs\12229709.docx" Call Openword(mydoc) End Sub
So far I have made the code that will open a specific file when the button on the form is clicked. However, there are a ton of these files that the user needs to be able to select and open. To keep it simple, I want them to be able to open the Word file by simply typing in the name of the file and clicking a button that will find and open it. The name of the file in the example above is simply 12229709.docx, but there are other files similar to it (e.g. 12172029, 12124057...) all in the same location. I want there to be a text box where the user can enter in the number and the button will check that specific folder for a file name with that number in it (without having to add the ".docx" if possible). How do I go about doing this?