I have a small client managment database on the go, and what I want to be able to do is add a button on the form which when clicked opens a file browser which allows the user to find and choose a quote (word doc). The filename/location is then added to a listbox/textbox on the form. Then there is a second button, which when clicked opens Word and then opens the document. The Sub I've made which opens the document works perfectly, but the filechoosing part doesn't seem to.
It drops the name/location of the file into a listbox, but once you move to another record in the database, it carries the same name/location across to that one. Basically it seems to hold one filename and once you close and open the database again, it's gone. What I want it to do basically is take the filename/location for each record and store it in my main table along with all the other customer details. Here is the 2 Subs I currently use (the first was borrowed from the MS knowledgebase pages)...
[tt]Private Sub cmdFileDialog_Click()
Dim fDialog As Office.FileDialog
Dim Varfile As Variant
FileList.RowSource = ""
FileList.RowSourceType = "Value List"
Set fDialog = Application.FileDialog(msoFileDialogFilePicker)
With fDialog
.AllowMultiSelect = False
.Title = "Please select a file"
.Filters.Clear
.Filters.Add "Word Document", "*.doc"
.Filters.Add "All Files", "*.*"
If .Show = True Then
For Each Varfile In .SelectedItems
FileList.AddItem Varfile
Next
Else
MsgBox "You didn't choose anything"
End If
End With
End Sub
Private Sub openQuote_Click()
Dim wdApp As Word.Application
Set wdApp = New Word.Application
' Check to see if a file has been selected
If IsNull(FileList) Then
MsgBox "You must select a file from the list"
End
Else
wdApp.Visible = True
wdApp.Documents.Open (FileList)
wdApp.ActiveWindow.SetFocus
Set wdApp = Nothing
End If
End Sub
[/tt]
Has anyone got any ideas as to why what's happening is happening, and even better a solution?
Thanks in advance
It drops the name/location of the file into a listbox, but once you move to another record in the database, it carries the same name/location across to that one. Basically it seems to hold one filename and once you close and open the database again, it's gone. What I want it to do basically is take the filename/location for each record and store it in my main table along with all the other customer details. Here is the 2 Subs I currently use (the first was borrowed from the MS knowledgebase pages)...
[tt]Private Sub cmdFileDialog_Click()
Dim fDialog As Office.FileDialog
Dim Varfile As Variant
FileList.RowSource = ""
FileList.RowSourceType = "Value List"
Set fDialog = Application.FileDialog(msoFileDialogFilePicker)
With fDialog
.AllowMultiSelect = False
.Title = "Please select a file"
.Filters.Clear
.Filters.Add "Word Document", "*.doc"
.Filters.Add "All Files", "*.*"
If .Show = True Then
For Each Varfile In .SelectedItems
FileList.AddItem Varfile
Next
Else
MsgBox "You didn't choose anything"
End If
End With
End Sub
Private Sub openQuote_Click()
Dim wdApp As Word.Application
Set wdApp = New Word.Application
' Check to see if a file has been selected
If IsNull(FileList) Then
MsgBox "You must select a file from the list"
End
Else
wdApp.Visible = True
wdApp.Documents.Open (FileList)
wdApp.ActiveWindow.SetFocus
Set wdApp = Nothing
End If
End Sub
[/tt]
Has anyone got any ideas as to why what's happening is happening, and even better a solution?
Thanks in advance