Getting Access records from a Word reference

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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?
 
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
 
Back
Top