Syntax issues for query

C

Colin Foster

Hi,
I've managed to get Access to send information directly to a Word document
filling in the necessary fields in the Word document as necessary (aren't
bookmarks wonderful!!).
Anyway, whilst that has worked perfectly well where there is only one result
that can appear in a field, I've come to an abrupt halt where there is more
than one option and I need to select a specific record that matches a set
criteria.
For example.. in TblContractors,
Contact 1 is an Architect
Contact 2 is a Builder
Both of these can appear within the same "contact" field within the access
database, so I have used "Contact" and "Type" to allow each to be shown. The
bit that I am struggling with is the syntax to allow me to put the Architect
in the Architects field within the word document and the Builder in the
Builder field.
I realise that I need to use something along the lines of
SELECT TblContractors.Type FROM TblContractors WHERE
(((TblContractors.Type)="Architect"));
However, how do I translate this to allow the selection from the contractors
form?
At the moment, I'm using...
.ActiveDocument.Bookmarks("Architect").Select
.Selection.Text = (CStr(Me.CustName))
and would like to have my "where" clause on the same line as the
..Selection.Text.
ANy suggestions?
 
C

Chris Nebinger

Would this work:

..ActiveDocument.Bookmarks(Me.Controls("Type")).Text = Cstr
(Me.CustName)


The word Type might be a reserved word, I'm not sure.
This will get the correct field even if it is.




Chris Nebinger
 
C

Colin Foster

Hi Chris,
Thanks for this, but I'm not sure how it would work.
In my Word document I have two bookmarks, one called "Architects", the other
"Builder", so when I run the code, I need to ensure that where there is a
contractor who is the Architect, their details go into the "Architects
field" in the word document and the Builder goes into the Builders field.
Your code suggestion (if I read it correctly) uses the current "Type" to
complete the "Bookmark" entry (e.g. if the current "Type" is "Architect",
then this will fill in "Architect" in the code then pull through the
"CustName" that matches this.
I wonder whether this would work...
..ActiveDocument.Bookmarks(Me.Controls("Type")="Architect").Text =
Cstr(Me.CustName)
and ...
..ActiveDocument.Bookmarks(Me.Controls("Type")="Builder").Text =
Cstr(Me.CustName)

Hmm...I'll try that a little later.

Regards
Colin
 
C

Chris Nebinger

Let's make sure we are talking about the same thing:

Table:

CustName Type
John Doe Architect
Jane Doe Builder


Word Document

2 bookmarks, one named Architect, the other Builder. The
data to be put in here is the CustName field.

Am I right? If so, then the solution I provided should*
work.


ActiveDocument.Bookmarks(Me.Controls("Type")).Text = CStr
(me.CustName)

For the first record, it would be:

ActiveDocument.Bookmarks("Architect").Text = "John Doe"

For the second:

ActiveDocument.Bookmarks("Builder").Text="Jane Doe"


Unless there is something else that I'm not understanding,
then it should* work.



*Should means I think it will, but not 100% sure.


Chris Nebinger
 
C

Colin Foster

Hi Chris,
Just tried it as originally suggested, but I get the following error...
"Compile Error: Method or data member not found"
The debugger window then opens showing the ".Text =" element of the code
highlighted.
Don't know if it makes any difference, but I'm using Access XP in the design
of this database.

With reference to the table structure, yes you are correct, however, will it
make any difference that I'm creating the word document from within a form?
Once again, thanks for your continuing assistance.
Regards
Colin
 
C

Chris Nebinger

Sending you an email...
If you dont' get it, you can send me one at my
(e-mail address removed)

Chris Nebinger
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top