Here's the scenario. I need to find a CustomerID for a Word customer record. I pull the Word customer info into an Access form and then try either DLookup or the Seek method (DAO) to find the CustomerID from a common unique identifier, ClassCode. That is, the Word record and the Access record both contain the unique ClassCode, but the Word record doesn't have the CustomerID. Sounds easy, doesn't it? However, neither method works, I suppose because the record source is ultimately the Word document even though the information is written to the Access form before the Seek method or DLookup is employed. The methods work fine when I setup an unbound form and manually enter the ClassCode so it's not the underlying table. Here's the A97 code:
'Get variable from Word file and place on form
Dim Wrd As Word.Application
Set Wrd = Word.Application
Dim rng as Range
Set rng = ActiveDocument.Sentences(6)
Me!ClassCode = rng
'This part works fine; the ClassCode appears on the form
'Seek CustomerID from ClassCode
Dim DB As Database
Dim rst As Recordset
Set DB = CurrentDb
Set rst = DB.OpenRecordset("Customer")
With rst
.Index = "ClassCode"
.Seek "=", Me!ClassCode
If .NoMatch Then
MsgBox "ClassCode not in database"
Else
Me!CustomerID = !CustomerID
End If
.Close
End with
Set rst = Nothing
I've tried indexing and then searching different fields and the result is the same; NoMatch is always true.
Any thoughts?
AvGuy
'Get variable from Word file and place on form
Dim Wrd As Word.Application
Set Wrd = Word.Application
Dim rng as Range
Set rng = ActiveDocument.Sentences(6)
Me!ClassCode = rng
'This part works fine; the ClassCode appears on the form
'Seek CustomerID from ClassCode
Dim DB As Database
Dim rst As Recordset
Set DB = CurrentDb
Set rst = DB.OpenRecordset("Customer")
With rst
.Index = "ClassCode"
.Seek "=", Me!ClassCode
If .NoMatch Then
MsgBox "ClassCode not in database"
Else
Me!CustomerID = !CustomerID
End If
.Close
End with
Set rst = Nothing
I've tried indexing and then searching different fields and the result is the same; NoMatch is always true.
Any thoughts?
AvGuy