Fill word with Ms Access (1 Viewer)

ZKHADI

Member
Local time
Tomorrow, 00:27
Joined
Apr 5, 2021
Messages
118
hey guys ! need help!

i got a code and i created a word document with textboxes.
i paste the code but it have some error could anybody fix it?
this code is about old version of Microsoft office and i am using 2013 .
see below image and check code
 

Attachments

  • Untitled.png
    Untitled.png
    135.6 KB · Views: 146

June7

AWF VIP
Local time
Today, 11:27
Joined
Mar 9, 2014
Messages
5,473
Copy/paste code into post between CODE tags, not image.
 

ZKHADI

Member
Local time
Tomorrow, 00:27
Joined
Apr 5, 2021
Messages
118
Code:
Function fillwordform()
Dim appword As word.Application
Dim doc As word.Document
Dim Path As String
On Error Resume Next
Error.Clear Path = "D:\College Database\Documents\CharacterCertificate.docx"
Set appWord = GetObject("word.application")
If Err.Number <> 0 Then
Set appWord = New word.Application
appWord.Visible = True
End If
Set doc = appWord.Documents.Open(Path, True)
With doc
.FormFields("StudentName").Result = Me.Student_name
'.FormFields("ClassNo").Result = Me
.FormFields("RegistrationNo").Result = Me.Board_University_Registration_No
.FormFields("Faculty").Result = Me.CurrentFacultySemester
.FormFields("Status").Result = Me.StudentStatus
End With
appWord.Visible = True
appWord.Activate
Set doc = Nothing
Set appWord = Nothing
End Function
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 03:27
Joined
May 7, 2009
Messages
19,245
you add Reference to Microsoft Word XX.XX Object Library in VBA.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 03:27
Joined
May 7, 2009
Messages
19,245
press Ctrl-G to go to VBA.
on Menu->Tools->References, you add
Microsoft Word XX.X Object Library (XX.X is the version number of your office).
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 03:27
Joined
May 7, 2009
Messages
19,245
it does not open, because you have Error there.
try this code:
Code:
Function fillwordform()
Dim appword As word.Application
Dim doc As word.Document
Dim Path As String
'On Error Resume Next
Error.Clear
Path = "D:\College Database\Documents\CharacterCertificate.docx"
Set appWord = GetObject("word.application")
If Err.Number <> 0 Then
Set appWord = New word.Application
'appWord.Visible = True
End If
Set doc = appWord.Documents.Open(Path, True)
With doc
.FormFields("StudentName").Result = Me.Student_name
'.FormFields("ClassNo").Result = Me
.FormFields("RegistrationNo").Result = Me.Board_University_Registration_No
.FormFields("Faculty").Result = Me.CurrentFacultySemester
.FormFields("Status").Result = Me.StudentStatus
End With
appWord.Visible = True
appWord.Activate
Set doc = Nothing
Set appWord = Nothing
End Function
 

ZKHADI

Member
Local time
Tomorrow, 00:27
Joined
Apr 5, 2021
Messages
118
it does not open, because you have Error there.
try this code:
Code:
Function fillwordform()
Dim appword As word.Application
Dim doc As word.Document
Dim Path As String
'On Error Resume Next
Error.Clear
Path = "D:\College Database\Documents\CharacterCertificate.docx"
Set appWord = GetObject("word.application")
If Err.Number <> 0 Then
Set appWord = New word.Application
'appWord.Visible = True
End If
Set doc = appWord.Documents.Open(Path, True)
With doc
.FormFields("StudentName").Result = Me.Student_name
'.FormFields("ClassNo").Result = Me
.FormFields("RegistrationNo").Result = Me.Board_University_Registration_No
.FormFields("Faculty").Result = Me.CurrentFacultySemester
.FormFields("Status").Result = Me.StudentStatus
End With
appWord.Visible = True
appWord.Activate
Set doc = Nothing
Set appWord = Nothing
End Function

problem fixed but the file open with empty textboxes.........
 

Attachments

  • Untitled.png
    Untitled.png
    86.7 KB · Views: 128

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 03:27
Joined
May 7, 2009
Messages
19,245
google and use Bookmark in Word.
 

HealthyB1

Registered User.
Local time
Tomorrow, 04:57
Joined
Jul 21, 2013
Messages
96
google and use Bookmark in Word.
Good morning.
I have been using the Function "FillwordForm" for many, many years and it has suddenly stopped working.
I have been beating my head against the wall trying find out why.
When the routine is run Word opens but with a grayed-out screen but no form. See attachment 1

I have put a break in the code and single stepped through it and also reentered lines of code to ensure that the pre-compiler is working.
Upon reviewing the VBA code in Attachment 2 it appears that the Item "Doc" is not being populated as hovering over it shows value is "Nothing"
Similarly in the Debug.Print statement nothing is returned.

I have checked the Word form that it references and it is in the correct place and the bookmarks are correct.

I have the same problem being exhibited on three different PC's

Can anyone please suggest why?
 

Attachments

  • AA FillwordForm Attachment 1.JPG
    AA FillwordForm Attachment 1.JPG
    73.3 KB · Views: 47
  • AA FillwordForm Issue Attachment 2.JPG
    AA FillwordForm Issue Attachment 2.JPG
    203.2 KB · Views: 43
Last edited:

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 03:27
Joined
May 7, 2009
Messages
19,245
try commenting out some codes:
Code:
    ...
    ...
    ...
    
    'Set appword = GetObject("word.application")
    
    'If Err.Number <> 0 Then
        Set appword = CreateObject("Word.Application")
        appword.Visible = True
    'End If
    
    ...
    ...
    ...
    
    'Set doc = Nothing
    'Set appword = Nothing
 

HealthyB1

Registered User.
Local time
Tomorrow, 04:57
Joined
Jul 21, 2013
Messages
96
Thanks Arnelgp
I commented out quite a few lines as you suggested and also added some Debug.Print statements.
If you look in the immediate window you will see that "Doc" does not contain anything???
Hovering over it in debug mode contents are always 'Nothing'
 

Attachments

  • AA FillwordForm Attachment 3.JPG
    AA FillwordForm Attachment 3.JPG
    175.2 KB · Views: 37

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 03:27
Joined
May 7, 2009
Messages
19,245
debug.print doc, won't show you anything since doc is an Object.
try to Step through the code.

also comment out:

'On Error Resume Next

so you can See what is the error.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 03:27
Joined
May 7, 2009
Messages
19,245
do you MS Word installed?
check the name and the path of of your word document.
do you have the path name correct and the filename correct?
 

HealthyB1

Registered User.
Local time
Tomorrow, 04:57
Joined
Jul 21, 2013
Messages
96
Hi Arnelgp.
Apologies for the delay. I have been working on other issues (Friday night drinks).
The good news is the problem is solved :)
After a lot of checking I eventually found that I had a Folder on Drive C: called 'swshare' and also a legacy share drive called 'swshare'.
I was working on word documents in swshare on the C: drive but it was somehow or other still looking at the old shared folder.
Once again a big thank you for all your help.

a
 

Users who are viewing this thread

Top Bottom