Microsoft Access Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMicrosoft Access Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old May 15th, 2008, 12:20 PM
Birkofas Birkofas is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 16 Birkofas User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 h 46 m 49 sec
Reputation Power: 0
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.

Reply With Quote
  #2  
Old May 15th, 2008, 04:07 PM
dykebert's Avatar
dykebert dykebert is offline
Contributing User
Click here for more information. Click here for more information
 
Join Date: Apr 2008
Posts: 348 dykebert User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 Days 10 h 53 m 31 sec
Reputation Power: 1
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.
Comments on this post
Birkofas agrees!

Reply With Quote
  #3  
Old May 15th, 2008, 07:57 PM
Birkofas Birkofas is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 16 Birkofas User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 h 46 m 49 sec
Reputation Power: 0
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

Reply With Quote
  #4  
Old May 16th, 2008, 09:14 AM
dykebert's Avatar
dykebert dykebert is offline
Contributing User
Click here for more information. Click here for more information
 
Join Date: Apr 2008
Posts: 348 dykebert User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 Days 10 h 53 m 31 sec
Reputation Power: 1
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?

Reply With Quote
  #5  
Old May 16th, 2008, 10:19 AM
Birkofas Birkofas is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 16 Birkofas User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 h 46 m 49 sec
Reputation Power: 0
Unhappy

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.

Reply With Quote
  #6  
Old May 16th, 2008, 01:49 PM
dykebert's Avatar
dykebert dykebert is offline
Contributing User
Click here for more information. Click here for more information
 
Join Date: Apr 2008
Posts: 348 dykebert User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 Days 10 h 53 m 31 sec
Reputation Power: 1
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.

Reply With Quote
  #7  
Old May 19th, 2008, 11:11 AM
Birkofas Birkofas is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 16 Birkofas User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 h 46 m 49 sec
Reputation Power: 0
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

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMicrosoft Access Development > Options groups for word doc


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT