Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL with parameters 1

Status
Not open for further replies.

jurgen

Programmer
Feb 8, 2001
209
BE
I've a form with 16 fields, continuous form, 6 tables behind it and now i'm truying to write a SQL statement where I can enter parameters (that are blanc unbound fields) in the form and then show the results.

Can you help me, or send me an example mdb ...

JJ
 
This might be of some use.

Command1_Click()

Dim qd
Dim strSQL as String
Dim strField1 as String ' For each field.

' Do this for each field...
txtField1.SetFocus
strField1 = txtField1.Text

' Build your SQL Statement...
strSQL = "SELECT * FROM tableName WHERE xyz=" & strField1 & " AND abc=" & strField2 & ";"

' You must have a query built before hand.
Set qd = CurrentDb.QueryDefs("QueryName")
qd.sql = strSQL
qd.Close

' Then call a macro that opens your report
DoCmd.RunMacro "MacroName"

If you need anymore information let me know.
 
You'll find some good sample code at MVPS.ORG.


There is also a good explanation at the following Microsoft link.

Access 97:

Access 2000:
Terry L. Broadbent
FAQ183-874 contains tips for posting questions in these forums.
NOTE: Reference to the FAQ is not directed at any individual.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top