Setting a Querey def

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a form with a print preview button (and print for that matter). when
a user clicks on the button, a report is to be previewed (printed) that
contains the information displayed. (taken from a field, CoilID) i've done
in the past some VBA where is make a string that contains the SQL statement
to select the proper record, but i forgot how. could someone help me out?
here's a bit of what i think.

Dim strRptQry As String
Dim dbsC1894 As Database
Dim rstRPTQRY as Recordset
Dim stDocName As String

strRptQry = "Select...."
strRptQry = strRptQry + "more stuff.."
'end of SQL statment string

Set dbsC1984 = CurrentDb
set rstRPTQRY = dbsC1894.OpenRecordset("qryReport")

rstRPTQRY.Open(srtRptQry)

stDocName = "rptScreen"
DoCmd.OpenReport stDocName, acPreview, ,

something along those lines. any help would be appreciated!
 
thanks, that helped. i just am wondering how to add a " into a string.

like str = "beginning of string with(")a quotation(") here"

i.e. i need quotation marks within the beginning/end quotations marks
denoting a string.
 
Replace the individual quotes with two quotes (""). If you are inserting
variables, this can look odd, but something like this:

Str = "Select * from MyTable where FirstName = """ & variable & """"

you can replace the the two quotes with an apostrophe:

Str = "Select * from MyTable where FirstName = '" & variable & "'"

--
--Roger Carlson
MS Access MVP
Access Database Samples: www.rogersaccesslibrary.com
Want answers to your Access questions in your Email?
Free subscription:
http://peach.ease.lsoft.com/scripts/wa.exe?SUBED1=ACCESS-L
 

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

Back
Top