|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Unbound form TxtBox for data entry to limit query records to 1
I have a db with a form that has code to access a query and send the result to a preformatted ms Word document. The code works fine except no matter what ID# is entered into the textbox, it always returns all the records instead of just the one entered into the box. I would like someone out there who is more familiar with code to look at the below code and give me an idea where I need to change (or add) lines to limit the search to one one record in the ID# field.
Thanks in advance. davedenn@sbcglobal.net Here's the code: Private Sub Text151_BeforeUpdate(Cancel As Integer) strSQL = " SELECT QryAdenCard.ID#, FROM QryAdenCard WHERE (((QryAdenCard.ID#)= '" & strID# & "));" 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(2).Close wdDoNotSaveChanges DoCmd.Hourglass False Set objWord = Nothing Set objDoc = Nothing End Sub |
|
#2
|
|||
|
|||
|
Why bother going through effort of writing a SQl statement (strSQL) if you aren't going to use it in you mail merge
SQLStatement:="SELECT * FROM [QryAdenCard]" Should be SQLStatement:=strSQL S- PS try to not use symbols in variables and Field Names, it is going to make you life harder down the road and it is a bad practice. The # symbol is also used to identify dates in SQL code for Access. |
![]() |
| Viewing: ASP Free Forums > Database > Microsoft Access Help > Unbound form TxtBox for data entry to limit query records to 1 |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|