Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Create Word document using VB 1

Status
Not open for further replies.

Djackola

Technical User
Jan 31, 2011
7
I have a database with 5000 client records
I setup a button in my form to create a folder for a client using the first name,Surname and Id fields in specific location ( Source folder) and other one to view the created folder. ( both codes listed below).
I'm writing letters to those clients using word application and my problem when I want to save the word file in a the client folder it take long time to find the client folder.
Is any way to setup a code to let me to lunch a word document in a client folder and to be saved there automatically.(eg. Click the create document button and it will create a word document in that directory) not in a specific location .


regards

Moawia

Private Sub CreateFolder_Click()
Dim strname As String
Dim strfname As String
On Error GoTo 1
strname = MemberName
strfname = MemberFamilyName
MkDir "C:\Users\Moawia\Desktop\sOURCE\" & strname & " " & strfname & "__" & ID
MsgBox (strname & " " & strfname & "__" & ID & " has been created successfully")
Exit Sub
1 MsgBox ("Could not create folder for this Client " & vbNewLine & "Folder may created already or " & vbNewLine & "Please check the Client's name and Client's family name.")
End Sub



Private Sub ViewFolder_Click()
Dim strname As String
Dim strfname As String
Dim path As String

On Error GoTo 1
strname = MemberName
strfname = MemberFamilyName
path = "Explorer.exe C:\Users\Moawia\Desktop\sOURCE\"
folder = strname & " " & strfname & "__" & ID
filename = path & strname & " " & strfname & "__" & ID
If Dir("C:\mainData\" & folder, vbDirectory) <> "" Then
Shell (filename), vbMaximizedFocus
Else
MsgBox ("Folder not exist")
End If
Exit Sub
1 MsgBox ("Could not view folder for this Client, folder may not exist.")
End Sub
 
save the word file in a the client folder it take long time
which code ?

Anyway, some discrepancy here:
path = "Explorer.exe C:\Users\Moawia\Desktop\sOURCE\"
vs
If Dir("C:\mainData\" & folder, vbDirectory) <> "" Then

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Not following.

"Is any way to setup a code to let me to lunch a word document in a client folder and to be saved there automatically.(eg. Click the create document button and it will create a word document in that directory) not in a specific location . "

Is not a directory (folder) a specific location? In any case, saving any file (Word or otherwise) requires a specific location.

247.50 hours to retirement
 
hi PHV

thanks ,
yes thats mistake sorry here the correct one

ifdir( C:\Users\Moawia\Desktop\sOURCE\" & folder, vbDirectory) <> "" Then

i think i didn’t put the question correctly because of my English again sorry for that

now I need you to help me finding a way (will not say code) to create a button in a form to create a word document in the client folder .
eg I have 10 records , I have a form to display the basic information for each record . In this form I created tow buttons , one to create folder and the other one to view the folder
I need a third button to lunch for me a word document in the record folder eg , if in the form im displaying a record which the first name john and surname is Murphy and the id is 25 , so the new folder name will be john murphy_25.
What I need a button to create for me a document in john murphy folder , because now if want to save a letter in john murphy folder I should first start word and then save as ,and this take very long time to find john murphy folder .

Hope this will help you understand what I need

Regards
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top