M
Mary
When I created a Macro to insert data from Access XP to
Word XP, it works. However, when I modify it to where
the user enters a value, and based on that value, will
insert data into Word I get this error:
run-time error '5922' word was unable to open data source
What is the problem? Below is the code:
Private Sub Document_Open()
Dim strDate As String
strDate = InputBox("enter date")
Selection.Range.InsertDatabase Format:=0, Style:=0,
LinkToSource:=False, _
Connection:= _
"Provider=Microsoft.Jet.OLEDB.4.0;Password="""";Us
er ID=Admin;Data
Source=H:\DeMiliaM\PRC\PRCTest.mdb;Mode=Read;Extended
Properties="""";Jet OLEDB:System database="""";Jet
OLEDB:Registry Path="""";Jet OLEDBatabase
Password="""";Jet OLEDB:Engine Type=5;Jet OLEDBa" _
, SQLStatement:= _
"SELECT `ID`, `Name`, `Age`, `Date` FROM `test`
WHERE ((`Date` >= #'strDate'#))" _
& "", PasswordDocument:="",
PasswordTemplate:="", WritePasswordDocument _
:="", WritePasswordTemplate:="", DataSource:= _
"H:\DeMiliaM\PRC\PRCTest.mdb", From:=-1, To:=-1,
IncludeFields:=True
End Sub
Word XP, it works. However, when I modify it to where
the user enters a value, and based on that value, will
insert data into Word I get this error:
run-time error '5922' word was unable to open data source
What is the problem? Below is the code:
Private Sub Document_Open()
Dim strDate As String
strDate = InputBox("enter date")
Selection.Range.InsertDatabase Format:=0, Style:=0,
LinkToSource:=False, _
Connection:= _
"Provider=Microsoft.Jet.OLEDB.4.0;Password="""";Us
er ID=Admin;Data
Source=H:\DeMiliaM\PRC\PRCTest.mdb;Mode=Read;Extended
Properties="""";Jet OLEDB:System database="""";Jet
OLEDB:Registry Path="""";Jet OLEDBatabase
Password="""";Jet OLEDB:Engine Type=5;Jet OLEDBa" _
, SQLStatement:= _
"SELECT `ID`, `Name`, `Age`, `Date` FROM `test`
WHERE ((`Date` >= #'strDate'#))" _
& "", PasswordDocument:="",
PasswordTemplate:="", WritePasswordDocument _
:="", WritePasswordTemplate:="", DataSource:= _
"H:\DeMiliaM\PRC\PRCTest.mdb", From:=-1, To:=-1,
IncludeFields:=True
End Sub