473,405 Members | 2,421 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

More Control While Opening Word

hi,
I am having a problem while providing more control while opening word..Below is the code where i am able to open the file. in this code when somebody clicks on command2 button a input box opens and it asks for CRC ID & then it opens the required docuemnt from the path as below.

But i want
1)if any CRCID is not found in the path, one msgbox will appear.
2) When somebody clicks on cancel button of input box. It should go to form only.

Kindly help me out with this problem. Thanx in Advance

Private Sub Command2_Click()
Dim intCRID, i As Integer
Dim StrFile As String
Dim appword As New Word.Application
intCRID = InputBox("CRC ID:", "OPEN CRC ANALYSIS DOCUMENT", "")
appword.Visible = True
appword.Documents.Open ("D:\projects\CRC MANAGEMENT\vb\" & intCRID & " .doc")
End Sub
Oct 6 '07 #1
9 1766
QVeen72
1,445 Expert 1GB
Hi,

To check the file exists or not use this code:

Expand|Select|Wrap|Line Numbers
  1. If Dir("D:\projects\CRC MANAGEMENT\vb\" & intCRID & " .doc",vbDirectory) <> "" Then
  2.    appword.Documents.Open ("D:\projects\CRC MANAGEMENT\vb\" & intCRID & " .doc")
  3. Else
  4.   Msgbox "Word Doc " intCRID & " Not Found "
  5. End If
  6.  
REgards
Veena
Oct 6 '07 #2
Hi,

To check the file exists or not use this code:

Expand|Select|Wrap|Line Numbers
  1. If Dir("D:\projects\CRC MANAGEMENT\vb\" & intCRID & " .doc",vbDirectory) <> "" Then
  2.    appword.Documents.Open ("D:\projects\CRC MANAGEMENT\vb\" & intCRID & " .doc")
  3. Else
  4.   Msgbox "Word Doc " intCRID & " Not Found "
  5. End If
  6.  
REgards
Veena

Thanx Veena,

i got my first questions answer. I am having another similar problem when i create a analysis document.

I want when i will click on cancel button of input box it should return to the form. Currently its giving me "runtime error 4198" i.e. command failed.

below is the code for the button.

Private Sub Command1_Click()
Dim appword As New Word.Application
Dim intCRID, i As Integer
Dim strDate, strFileName As String
Dim Range As Range
'Define the path where to save the CR.doc
intCRID = InputBox("CRC ID:", "Create ANALYSIS Document", "")
strDate = Format(Now(), "yyyy-mm-dd")
strFileName = "CR " & intCRID & " cr.doc"
'Open the RMA Word Template
appword.Documents.Open ("D:\projects\CRC MANAGEMENT\vb\CR.doc")
' Make Word visible through the Application object.
appword.Visible = True
' Save the new CRID document
appword.ActiveDocument.SaveAs "D:\projects\CRC MANAGEMENT\vb\" & intCRID & " .doc"
End Sub
Oct 6 '07 #3
QVeen72
1,445 Expert 1GB
Hi,

When Cancel is Clicked, the Return value from Inputbox is empty,
you can check :

When you have declared intCrID as Integer, you need to take Val of InputBox,
And Check For
intCrID = 0



Regards
Veena
Oct 6 '07 #4
No dear its not working.
Again the same kind of error is coming.
Oct 6 '07 #5
QVeen72
1,445 Expert 1GB
Hi,

Write appropriate Error Handler..

In your Code at the beginning, write "On Error Resume Next"
and before end sub , write this code :

Expand|Select|Wrap|Line Numbers
  1. If Err.Number = 4198 Then 
  2.     objwordapp.Quit 
  3.     MsgBox "User cancelled" 
  4. End If 
  5.  
Regards
Veena
Oct 6 '07 #6
Thats fine Veena. I think you got it right.

But what i want is that after canceling the input box it should not resume to the next step i.e. opeing the word file. But it should go the mainform.
Oct 6 '07 #7
QVeen72
1,445 Expert 1GB
Hi,

write this after InputBox :

Dim intCRID As String

intCRID = InputBox("CRC ID:", "Create ANALYSIS Document", "")
If Trim(intCrID) ="" Then
' Write Unload Me/ Or any other function to exit
'
Exit Sub
End If

REgards
Veena
Oct 6 '07 #8
Hi,

write this after InputBox :

Dim intCRID As String

intCRID = InputBox("CRC ID:", "Create ANALYSIS Document", "")
If Trim(intCrID) ="" Then
' Write Unload Me/ Or any other function to exit
'
Exit Sub
End If

REgards
Veena


Thanx very much Veena.Without your support i couldn't have submited this project. I think it was a great help from you that i am about to complete this project by monday only. Thanx a lot again for your great support.
Oct 6 '07 #9
QVeen72
1,445 Expert 1GB
Hi,

You are always welcome.
Glad you could complete your project on time.

Regards
Veena
Oct 6 '07 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

303
by: mike420 | last post by:
In the context of LATEX, some Pythonista asked what the big successes of Lisp were. I think there were at least three *big* successes. a. orbitz.com web site uses Lisp for algorithms, etc. b....
0
by: Sivaraman.S | last post by:
Issue: When I am opening a word document or a template from an ASP.NET Web page (language used VB.NET Visual Studio Version 2003) using Word.ApplicationClass object (Reference Word 11.0 object...
6
by: Colleyville Alan | last post by:
I have an application that has an Access table that stores the locations of slides in a Powerpoint file. This used to work fine when there were about 4 files and 200 slides. The database would...
1
by: Andy Davis | last post by:
Hi I've written the following code for a button on a form to open a mail merge document in MS Word. The code opens the document fine but does not display the usual connection details to open the...
1
by: Ryan Ternier | last post by:
We're looking for a 3rd party control that will take a Word (2000, xp, 2003) document / Excel document and convert it to HTML. Currently, we're opening up a copy of word on our servers, opening...
13
by: Deano | last post by:
Apparently you can only do this with one value i.e Call MyAssetLocationZoom(Me!txtLocation, "Amend data") This runs; Public Sub MyAssetLocationZoom(ctl As Control, formName As String) On...
2
by: Colin Halliday | last post by:
I have a Word 2003 mail merge main document (form letter) that is linked to another Word document data source for the mail merge. If I open this doc using the Word GUI, it first asks me to...
5
by: Cedric | last post by:
Hi Folks, I'm wondering if someone has already succeed to open a word2000 document located on server side with javascript code executed by a web browser on client side. In fact, i make it...
1
navanova
by: navanova | last post by:
Greetings, I have a problem of opening ms word and excel files on my computer. The files are there for a long time. I use to open and modify them. Suddenly, when i try to open the word files, a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.