Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Modules / DAO / VBA / September 2006

Tip: Looking for answers? Try searching our database.

Getting Access records from a Word reference

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Ian on Cowan - 25 Sep 2006 20:26 GMT
Problem: A Word doc contains words (usually in a footnote, but doesn't have
to be), which are keys to records in an Access database. How can these Access
records be displayed when the Word items are clicked, or selected and
clicked?
Tim Ferguson - 26 Sep 2006 19:46 GMT
=?Utf-8?B?SWFuIG9uIENvd2Fu?= <IanonCowan@discussions.microsoft.com>
wrote in news:63F94C01-F2FF-44C4-B67F-74FD0448C0AE@microsoft.com:

> Problem: A Word doc contains words (usually in a footnote, but doesn't
> have to be), which are keys to records in an Access database. How can
> these Access records be displayed when the Word items are clicked, or
> selected and clicked?

I don't think that Word has a MouseClick event... you could use the
Selection object and a ctrl-key or toolbar button to call the code. This
is very obviously air code. You'd be better off asking this in a Word
programming group.

public sub LookItUp

 dim dbe as DBEngine ' needs reference to DAO.
 dim db as database  ' ditto
 dim jetSQL as string
 dim rs as Recordset

 dim rng as range

 ' get the user selection
 set rng = activewindow.selection.range
 ' bug out if it's not exactly one word
 if rng.words.count <> 1 Then exit sub

 ' get the database
 set dbe=new DBEngine
 set db = dbe.OpenDatabase(pathToMyDatabase, false, true)

 ' look up the word
 jetSQL = "SELECT Something FROM MyTable " & _
   "WHERE TheWord = """ & rng.Text & """;"
 set rst=db.OpenRecordset(jetSQL, dbOpenSnapshot, dbForwardOnly)

 ' respond to the user
 if rst.EOF then
   msgbox "Sorry, can't find that word"

 else
   msgbox "That word returned: """ & rst!Something & """"

 End if

 ' clean up database objects
 rst.Close
 db.Close

End Sub

... or something like that. Hope it helps

Tim F
Ian on Cowan - 26 Sep 2006 19:56 GMT
Many thanks Tim, there's definitely something to try there!

> =?Utf-8?B?SWFuIG9uIENvd2Fu?= <IanonCowan@discussions.microsoft.com>
> wrote in news:63F94C01-F2FF-44C4-B67F-74FD0448C0AE@microsoft.com:
[quoted text clipped - 50 lines]
>
> Tim F
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.