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

Change SQL to Code

Status
Not open for further replies.

PamSt

Technical User
Nov 27, 2002
9
I have a customer database and I'm trying to change some SQL in to code. I have a
customer form with a subform and I need information from both to open another
form. My SQL minis the fields read

FROM Customer INNER JOIN Orders ON Customer.CustomerNumber =
Orders.CustomerNumber
WHERE
((([Customer]![CustomerNumber])=[Forms]![NewOrder]![CustomerNumber]) AND
(([Orders]![OrdersNumber])=[Forms]![NewOrder].[OrSub].[Form]![OrderNumber]));

I open the form with this query and it works fine but I would like to write it in code. I
tried to write it like this:
DoCmd.OpenForm "ExpOrders",,, "CustomerNumber = '"& Me!CustomerNumber& "'
And
OrderNumber = '"& Me!OrSub.Form!OrderNumber & "'"
I use this and I keep getting Errors, can anyone see what I'm doing wrong.
Thanks Pam.
 
Hi
I previously replied on 27th in vb(microsoft)Databases forum. Heres a repost
Two suggestions to start you off -
Try using a . (decimal point) not the ! (exclamation mark)
and put a space in front of the & characters.

Or if this does not work let me know details of the errors you get

cjw
 
Pam: Concatanate the SQL in one line, ending with a colon;
This usually works for me, indeed, I create many queries and then cut and paste the SQL into the vba code behind of the forms. What I usually do fist in the SQL view of the query is hit the delete key at the end of each line and then copy and paste the entire line in the code of the form where I want it. 9 out of 10 times I have no problem with this.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top