I have posted this question before, but did not find a viable solution to my siuation so I am posting it again in the hopes that someone out there will have an answer.
I have a db with a form that is the data entry point for two linked tables. The tables are linked through a primary key of "PatientID." I have created a query via VB code that sucessfully queries the tables and return all records. I have attached the code to an unbound text box in the form. I would like to set the code up so that a user can enter the Patient ID into the text box and 1 record will be returned to a mailmerge formatted MS Word document. At this point, all records merge into the document creating 3-4 pages of data each. I have posted the existing code below and hope that someone out there can provide a solution to my problem. I have tried a DLookUp statement and a Where statement without success.
Here's the code. Please respond to my email address if you have a suggestion or solution. Thanks in advance for any help you can provide.
davedenn@sbcglobal.net
Private Sub Text151_BeforeUpdate(Cancel As Integer)
Dim objWord As Word.Document
Set objWord = GetObject("C:\aden.doc", "Word.Document")
objWord.Application.Visible = True
objWord.MailMerge.OpenDataSource _
Name:="C:\DoctorDB.mdb", _
LinkToSource:=True, _
Connection:="QUERY QryAdenCard", _
SQLStatement:="SELECT * FROM [QryAdenCard]"
objWord.MailMerge.Execute
'objWord.Application.Documents(1).SaveAs (strDir & "\" & strReportType & ".doc")
objWord.Application.Documents(2).Close wdDoNotSaveChanges
DoCmd.Hourglass False
Set objWord = Nothing
Set objDoc = Nothing
End Sub
I have told that the * in the Select statement returns all the records, I just can't seem to come up with an alternative that returns the one records that I need.
I have a db with a form that is the data entry point for two linked tables. The tables are linked through a primary key of "PatientID." I have created a query via VB code that sucessfully queries the tables and return all records. I have attached the code to an unbound text box in the form. I would like to set the code up so that a user can enter the Patient ID into the text box and 1 record will be returned to a mailmerge formatted MS Word document. At this point, all records merge into the document creating 3-4 pages of data each. I have posted the existing code below and hope that someone out there can provide a solution to my problem. I have tried a DLookUp statement and a Where statement without success.
Here's the code. Please respond to my email address if you have a suggestion or solution. Thanks in advance for any help you can provide.
davedenn@sbcglobal.net
Private Sub Text151_BeforeUpdate(Cancel As Integer)
Dim objWord As Word.Document
Set objWord = GetObject("C:\aden.doc", "Word.Document")
objWord.Application.Visible = True
objWord.MailMerge.OpenDataSource _
Name:="C:\DoctorDB.mdb", _
LinkToSource:=True, _
Connection:="QUERY QryAdenCard", _
SQLStatement:="SELECT * FROM [QryAdenCard]"
objWord.MailMerge.Execute
'objWord.Application.Documents(1).SaveAs (strDir & "\" & strReportType & ".doc")
objWord.Application.Documents(2).Close wdDoNotSaveChanges
DoCmd.Hourglass False
Set objWord = Nothing
Set objDoc = Nothing
End Sub
I have told that the * in the Select statement returns all the records, I just can't seem to come up with an alternative that returns the one records that I need.