|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Options groups for word doc
Hi All
I have several word documents as template. I created options groups to open one of the selected document. I am trying wright a vba code, but I think I have not enough knowledge about it. Can anyone help me wright a code? Please. |
|
#2
|
||||
|
||||
|
Well what you want to do is in the AfterUpdate event for the Option box (frame) you want something like this:
Dim fileName as String Select Case Me.wordTmpltOption Case 1 fileName = "word template 1" Case 2 filename = "word template 2" ... End Select <open MS Word doc> <filePath> & fileName I forget the syntax for opening an MS Word document but you should be able to look it in Help. If you have a problem, I'll dig it up. |
|
#3
|
|||
|
|||
|
This is my code. But it does not work, suppose there are some mistakes. It always shows run time error 2465.
Private Sub cmdOpenTemplate_Click() On Error GoTo Err_cmdOpenTemplate Dim FileName As String Dim docWord As Word.Document Select Case Me!optgrpReportOption Case 1 FileName = "Template For Individual Personal Information.doc" Case 2 FileName = "Group timetable.doc" Case 3 FileName = "Evaluation Form.doc" Case 4 FileName = "Questionnaire.doc" End Select OpenWord FileName = CurrentProject.Path & "\Template For Individual Personal Information.doc" Set docWord = objWord.Documents.Open(FileName) Exit_cmdOpenTemplate: Exit Sub Err_cmdOpenTemplate: MsgBox "Error no. " & Err.Number Resume Exit_cmdOpenTemplate End Sub Is it would be better if I put my code on after update event on the option frame? And one more question. I have four different word doc, do I have put them all in one path line and separate with comma ? Can you help me sort it out, please? Thanks for the given ideas |
|
#4
|
||||
|
||||
|
well the one thing I can see is the line
OpenWord If that is meant as a comment then it should have a ' in front of it. When you step through the code do you get the error on a particular line or does it not even start the procedure? |
|
#5
|
|||
|
|||
|
OpenWord it is a comment, you are right.
When I steping through the code I getting error 2465 and it not even starting the procedure. ![]() |
|
#6
|
||||
|
||||
|
Well I'm not sure what error 2465 is, but here is the basic code that worked for me.
Dim wrdApp As Word.Application Set wrdApp = CreateObject("Word.Application") wrdApp.Documents.Open "<filename>" Set wrdApp = Nothing I'm assuming you have added the reference to the MS Word object library. |
|
#7
|
|||
|
|||
|
Thanks for your help and for your ideas dykebert.
This is my code. It works now. Private Sub cmdOpenTemplate_Click() Dim Filenames As String Dim oApp As Object Select Case Me!optgrpReportOption Case 1 Filenames = "Individual Personal Information" Case 2 Filenames = "Group timetable" Case 3 Filenames = "Evaluation" Case 4 Filenames = "Questionnaire" End Select 'OpenWord If Me!optgrpReportOption = 1 Then Filenames = CurrentProject.Path & "\Template For Individual Personal Information.doc" Else If Me!optgrpReportOption = 2 Then Filenames = CurrentProject.Path & "\Group timetable.doc" Else If Me!optgrpReportOption = 3 Then Filenames = CurrentProject.Path & "\Evaluation Form.doc" Else If Me!optgrpReportOption = 4 Then Filenames = CurrentProject.Path & "\Questionnaire.doc" End If End If End If End If If (Dir(Filenames) = "") Then MsgBox "Document not found." Else Set oApp = CreateObject("Word.Application") oApp.Visible = True 'Open the Document oApp.Documents.Open FileName:=Filenames End If Exit_cmdOpenTemplate: Exit Sub Err_OpenWordDoc: MsgBox "Error no. " & Err.Number Resume Exit_cmdOpenTemplate End Sub |
![]() |
| Viewing: Dev Articles Community Forums > Databases > Microsoft Access Development > Options groups for word doc |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|