Create .docx in the path specified in a field of a table with a button (1 Viewer)

DreamerArgentino

New member
Local time
Today, 04:57
Joined
May 19, 2018
Messages
26
Hi everyone! I have an "attachmets" table that stores the paths in a "Path" field of .pdf files used in a given record. What you would need is:
1- At the push of a button, a new .docx opens

2- That the same .docx take the name of a field "NunberReg" of the Main Form "MyForm" and be saved in the same path as the .pdf files of the current record, that is, in "Path"

3-
and that, in addition to taking the name of a field "NunberReg" of the Main Form "MyForm", inject the text forward: "Procedure".
For example, the full name of the .docx would look like this: "Procedure - (NumberReg).docx"

I hope you can help me, in advance, thank you very much!
 

oleronesoftwares

Passionate Learner
Local time
Today, 04:57
Joined
Sep 22, 2014
Messages
1,159
Function expord_ASL_to_word()
On Error GoTo expord_ASL_to_word_Err
Dim networkPath As String

networkPath = "C:\Your\Network\Path\"

exportPath = networkPath & Forms!Form1!SerialComboBox.Value & " " & Forms!Form1!VendorComboBox.Value & " ASL.docx"

DoCmd.OutputTo acOutputQuery, "Match up", "Worddocument(*.docx)", exportPath, True, "", , acExportQualityPrint

expord_ASL_to_word_Exit:
Exit Function

expord_ASL_to_word_Err:
MsgBox Error$
Resume expord_ASL_to_word_Exit
End Function
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 19:57
Joined
May 7, 2009
Messages
19,175
on this sample db, open attachment table and edit (don't forget to add \ at the end of the path).
 

Attachments

  • docx_path.accdb
    472 KB · Views: 351

DreamerArgentino

New member
Local time
Today, 04:57
Joined
May 19, 2018
Messages
26
on this sample db, open attachment table and edit (don't forget to add \ at the end of the path).
Hello arnelgp!! Thanks a lot! Its exactly i need!
I would need to see it well to make some changes, I hope I can do it, otherwise I will consult you again!
A big hug!
 

DreamerArgentino

New member
Local time
Today, 04:57
Joined
May 19, 2018
Messages
26
on this sample db, open attachment table and edit (don't forget to add \ at the end of the path).
Hello arnelgp!!
I bother you again because I need to know how could I modify it so that when I click on the button, also do the following:

That the .docx be open from a default location (for example an attachment in the same BD as template.dot) and is immediately and automatically saved in a specified path (P:\Notes\) and the value of that (path + name) of the created file is injected (for example in: P:\Notes\Procedure (Nr00120).docx) in the "FullFileName" FIELD of a TABLE named "Path-NA"

Thanks in advance!!
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 19:57
Joined
May 7, 2009
Messages
19,175
you open the word template first and save it to your template path
as normal document (.docx).

now you add another field to your "path" table (say, Template).
you then fill this field with the correct path + filename of your template.

see this demo again, extract all files on same folder.
when the form opens, it will update the "path" table of
the location+filename of my sample template.
(you do not need to do this in your code if you
already assigned the fixed location of your template).
 

Attachments

  • dox_path.zip
    120.5 KB · Views: 295

DreamerArgentino

New member
Local time
Today, 04:57
Joined
May 19, 2018
Messages
26
you open the word template first and save it to your template path
as normal document (.docx).

now you add another field to your "path" table (say, Template).
you then fill this field with the correct path + filename of your template.

see this demo again, extract all files on same folder.
when the form opens, it will update the "path" table of
the location+filename of my sample template.
(you do not need to do this in your code if you
already assigned the fixed location of your template).
Hello @arnelgp !! You have interpreted me to perfection! Thank you very much for dedicating your time, I value it very much, it has been a great help! A hug. Dreamer.-
 

DreamerArgentino

New member
Local time
Today, 04:57
Joined
May 19, 2018
Messages
26
you open the word template first and save it to your template path
as normal document (.docx).

now you add another field to your "path" table (say, Template).
you then fill this field with the correct path + filename of your template.

see this demo again, extract all files on same folder.
when the form opens, it will update the "path" table of
the location+filename of my sample template.
(you do not need to do this in your code if you
already assigned the fixed location of your template).

Hello armelgp! Here again bothering you.


I have the need to place the button 'cmdCreateDocx' inside a Subform, but that the TextBox 'NumberReg' is still in the main form 'Form1', which is where it would take the data to generate the name of the .docx.

How do I reference that textbox from the subform button?



Note: the TextBox 'NumberReg' (takes the data from a table called TABLE1)


I have tried several things, and it generates different errors ... I tried things like: Me. [TABLE1]![NumberReg] instead of the one in your code which is Me.NumberReg, (which is in the 'Attachments' table), I don't know if I'm on the right track ...



Thank you in advance
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 19:57
Joined
May 7, 2009
Messages
19,175
you need to reference the NumberReg using the Parent property of the subform:
Code:
Private Sub cmdCreateDocx_Click()
Dim wdApp As Object     'Word.Application
Dim wdDoc As Object     'Word.Document
Dim sFilename As String, sRegNumber As String
On Error GoTo err_handler
sRegNumber = Me.Parent!NumberReg & ""
If Len(sRegNumber) < 1 Then
    MsgBox "Please provide the Registration number."
    Me.NumberReg.SetFocus
    Exit Sub
End If
sFilename = DLookup("path", "attachments") & "Procedure (" & sRegNumber & ").docx"

If Len(Dir$(sFilename)) <> 0 Then
    If MsgBox("File 'Procedure (" & Me.NumberReg & ").docx' already exists." & vbCrLf & _
        "Overwrite it?", vbQuestion + vbYesNo) = vbNo Then
        Exit Sub
    End If
    Kill sFilename
End If

' copy Template.doc to the folder
' 08-dec-2021
'
VBA.FileCopy DLookup("template", "attachments"), sFilename
CreateObject("Shell.Application").Namespace(0).ParseName(sFilename).InvokeVerb ("Open")

exit_sub:
    Exit Sub
err_handler:
    MsgBox Err.Number & vbCrLf & Err.Description
    Resume exit_sub
End Sub
 

DreamerArgentino

New member
Local time
Today, 04:57
Joined
May 19, 2018
Messages
26
you need to reference the NumberReg using the Parent property of the subform:
Private Sub cmdCreateDocx_Click()
Dim wdApp As Object 'Word.Application
Dim wdDoc As Object 'Word.Document
Dim sFilename As String, sRegNumber As String
On Error GoTo err_handler
sRegNumber = Me.Parent!NumberReg & ""
If Len(sRegNumber) < 1 Then
MsgBox "Please provide the Registration number."
Me.NumberReg.SetFocus
Exit Sub
End If
sFilename = DLookup("path", "attachments") & "Procedure (" & sRegNumber & ").docx"

If Len(Dir$(sFilename)) <> 0 Then
If MsgBox("File 'Procedure (" & Me.NumberReg & ").docx' already exists." & vbCrLf & _
"Overwrite it?", vbQuestion + vbYesNo) = vbNo Then
Exit Sub
End If
Kill sFilename
End If

' copy Template.doc to the folder
' 08-dec-2021
'
VBA.FileCopy DLookup("template", "attachments"), sFilename
CreateObject("Shell.Application").Namespace(0).ParseName(sFilename).InvokeVerb ("Open")

exit_sub:
Exit Sub
err_handler:
MsgBox Err.Number & vbCrLf & Err.Description
Resume exit_sub
End Sub
Hello arnelgp !! Once again, thank you for your valuable input!

I used your code and it generates compilation error in the part highlighted in bold; so I replaced it with 'Me.Parent! NumberReg' in both cases and it worked perfectly, I don't know if I understood the concept or it was just luck haha.

Thanks again!
Dreamer.-
 
Last edited:

DreamerArgentino

New member
Local time
Today, 04:57
Joined
May 19, 2018
Messages
26
you need to reference the NumberReg using the Parent property of the subform:
Code:
Private Sub cmdCreateDocx_Click()
Dim wdApp As Object     'Word.Application
Dim wdDoc As Object     'Word.Document
Dim sFilename As String, sRegNumber As String
On Error GoTo err_handler
sRegNumber = Me.Parent!NumberReg & ""
If Len(sRegNumber) < 1 Then
    MsgBox "Please provide the Registration number."
    Me.NumberReg.SetFocus
    Exit Sub
End If
sFilename = DLookup("path", "attachments") & "Procedure (" & sRegNumber & ").docx"

If Len(Dir$(sFilename)) <> 0 Then
    If MsgBox("File 'Procedure (" & Me.NumberReg & ").docx' already exists." & vbCrLf & _
        "Overwrite it?", vbQuestion + vbYesNo) = vbNo Then
        Exit Sub
    End If
    Kill sFilename
End If

' copy Template.doc to the folder
' 08-dec-2021
'
VBA.FileCopy DLookup("template", "attachments"), sFilename
CreateObject("Shell.Application").Namespace(0).ParseName(sFilename).InvokeVerb ("Open")

exit_sub:
    Exit Sub
err_handler:
    MsgBox Err.Number & vbCrLf & Err.Description
    Resume exit_sub
End Sub
Hello arnlgp!

I keep coming up with ideas that I don't know how to materialize.

How can I make the path created by the button "cmdCreateDocx" and its file name (obviously), are "injected" into the "FullFileName" field of the "AttachmentsReceived" Table?

Here I attach the base already modified with the subform and some more changes

Thanks!
 

Attachments

  • dox_path+Subform00.zip
    463.9 KB · Views: 337

DreamerArgentino

New member
Local time
Today, 04:57
Joined
May 19, 2018
Messages
26
test this db.

Hello arnelgp !!

I'm embarrassed to have to bother you one more time, but I've honestly tried dozens of things that didn't work for me. Maybe you can give me an idea.

What remains to be done is:

By pressing the 'cmdCreateDocx' button at the moment it checks if the file already exists in the 'Attachments' Folder, and displays a Dialog Box: Overwrite existing YES / NO ?; where obviously if I choose NO, it does nothing and YES, it overwrites it.

Continuing from the point where I press NO, I need to appear, for example, another dialog box that gives the option to create a new '.docx' in the same Folder 'Attachments', and as before also inject the path + name in FullFileName, but with a different name than the existing one and with the possibility of editing it, for example:

'(EnterText) Procedure (500) .docx'

Note: The important thing and what I need, is that all the .docx that are created with the button, are saved both in the 'FullFileName' field of the 'AttachmentsReceived' table and in the 'Attachments' folder. Other similar alternatives are accepted :)

Thank you very much,
Dreamer.-
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 19:57
Joined
May 7, 2009
Messages
19,175
can you post the Code you have on the button so i can see where
can i insert some code?
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 19:57
Joined
May 7, 2009
Messages
19,175
you test again.
 

Attachments

  • docx_path.accdb
    968 KB · Views: 311

Users who are viewing this thread

Top Bottom