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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL from Query to code

Status
Not open for further replies.

cneill

Instructor
Mar 18, 2003
210
GB
Below is the sql from my query

SELECT tblAccountSchemes.SiteID, tblAccountSchemes.SchemeID, TblScheme.Scheme, TblScheme.SortOrder
FROM TblScheme INNER JOIN tblAccountSchemes ON TblScheme.SchemeID = tblAccountSchemes.SchemeID
WHERE (((tblAccountSchemes.SiteID)=[Forms]![FrmMainAccountSchemes]![txtNodeKey]))
ORDER BY tblAccountSchemes.SiteID, TblScheme.SortOrder;

I want it to run from code I tried using
Docmd.Runsql but I could not get it to work can some one show me where I am going wrong
 
Docmd.Runsql only works with action queries. Select is not an action query.


Ian Mayor (UK)
Program Error
9 times out of 10 I know what I'm talking about. This must be my tenth reply.
 
You are missing a few arguments in the Docmd command.

In your code declare the sql above as strSQL. then say Docmd.runsql and the required arguments
 
I agree with ProgramError. cneill it is best to say what you wish to achieve.

 
Think of "SELECT ..." as a function** in VB. It returns a value (specifically, it returns a recordset which will contain zero or more records.) You must use a construct that provides a place to store that returned value.

Something More like
Code:
Dim db As DAO.Database
Dim rs As DAO.Recordset
Set db = CurrentDb
Set rs = db.OpenRecordset(... Your SELECT Statement ...)

** - Apologies to the purists. It's only an analogy ... not to be taken too literally.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top