Problem with strSQL

H

Hilary Ostrov

This is my first attempt at creating a strSQL (to use with Albert
Kallal's wonderful WordMerge!) and I seem to be doing something wrong:

Private Sub cmdWordMerge_Click()
Dim strSQL As String
If IsNull(Me.cboJobsite) = False Then

strSQL = "SELECT Jobsites!Site_Name," & "Jobsites!Site_Address," &
"Jobsites!City," & "Jobsites!PostalCode" & "FROM Jobsites " &
"WHERE(Jobsites!SiteID = & me.cboJobsite)"

MergeAllWord strSQL

End If
End Sub

Access (2003) seemed to think it's OK (or I assume it did, since I
wasn't getting any compile errors, but that may be unwarranted
optimism on my part!), but I'm getting a msg prompt from Albert's
program indicating that there's a problem with the above SQL
statement.

If someone could show me the error of my ways, I would be eternally
grateful :)

Thanks.
hro
 
A

Albert D. Kallal

Try:

Private Sub cmdWordMerge_Click()
Dim strSQL As String
If IsNull(Me.cboJobsite) = False Then

strSQL = "SELECT Site_Name, Site_Address, City, PostalCode " & _
"FROM Jobsites where SiteID = " & me.cboJobsite

MergeAllWord strSQL

End If
End Sub

Remember, you are building a standard sql statement here. This statement has
NO attachment to your your form now.....

(and, you can/could use a query that you build with the above also - however
the so called "in-line" sql as above should be ok)

The above does assume that SiteID and me.cboJobSite are a number type field
 
H

Hilary Ostrov

On Sun, 26 Nov 2006 17:08:00 -0700, in
<[email protected]>, "Albert D. Kallal"

Many thanks, Albert. It didn't work, but

strSQL = "SELECT * " & _
"FROM Jobsites WHERE Jobsites.ID = " & Me.cboJobsite

does work [SiteID is actually a txt field, so I changed my cboJobsite
query to include Jobsite.ID autonumber field], and I just select the
fields I want in my Word template :)
Try:

Private Sub cmdWordMerge_Click()
Dim strSQL As String
If IsNull(Me.cboJobsite) = False Then

strSQL = "SELECT Site_Name, Site_Address, City, PostalCode " & _
"FROM Jobsites where SiteID = " & me.cboJobsite

MergeAllWord strSQL

End If
End Sub

[...]
hro
 

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

Similar Threads

Combo question 2
Word Merge SQL syntax 1

Top