Generate filename based on specific fields

ro801

Registered User.
Local time
Yesterday, 23:52
Joined
Apr 12, 2012
Messages
24
I have successfully managed to generate a Word document using automation from Access 2003. The next step is to be able to save the file in a manner and location that is appropriate for my needs. The documents are specific to individual patients and as such need to reflect this in their filenames and where they are eventually kept. I am trying to figure out a way of adding a macro that will take the "Hospital Number" and "Case Number" and combine them with a rough title (such as "Initial Letter") = 123456-31-InitialLetter and then save them into a folder (or created if it doesn't already exist) named the same as the "hospital number". However, I have no idea how to accomplish this, can i re-interrogate the still open database for this data? If so how? I have managed (by use of automation again) to add the above combination filename to a part of the document, can i reference that in the actual filename? If so how can i tell the code to do this? Alternatively, is it best to name the file as it's initially created? I've used the code below as an event procedure on a command button in the form to generate the letter; can anyone shed any light on what might need to be added to it to accomplish my goal. Many thanks in advance anyone who has the time and patience to help me with this. The code i mentioned:

Private Sub MergeButton___Click()
On Error GoTo MergeButton_Err

Dim objWord As Word.Application


'Start Microsoft Word.
Set objWord = CreateObject("Word.Application")

With objWord
'Make the application visible.
.Visible = True
objWord.Activate

'Open the document.
.Documents.Open ("C:\Users\OR\Documents\Initial Document.doc")

'Move to each bookmark and insert text from the form.
.ActiveDocument.Bookmarks("DCCVUN").Select
.Selection.Text = (CStr(Forms!DCCVFORM!DCCVUN))
.ActiveDocument.Bookmarks("DCCVCASENUMBER").Select
.Selection.Text = (CStr(Forms!DCCVFORM!DCCVCASENUMBER))

End With


Exit Sub

MergeButton_Err:
'If a field on the form is empty, remove the bookmark text, and
'continue.
If Err.Number = 94 Then
objWord.Selection.Text = ""
Resume Next

End If

Exit Sub

End Sub
 

Users who are viewing this thread

Back
Top Bottom