473,425 Members | 1,842 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,425 software developers and data experts.

Correctly format where statement in query

imrosie
222 100+
Hello Experts,

It's going to take one to figure this out. My Order form is supported by a query of two tables (Customers and Orders). There is a subform within the Form for entering in the new Order infor, so I need both tables in the query. A customer is first selected through a combo box on the Order frm to begin new Order. Unfortunately, I can't bring up a newly added customer name IF that Customer doesn't have a prior order. Otherwise the combo can bring up any customer. Here's the SQL statement:

Expand|Select|Wrap|Line Numbers
  1. SELECT DISTINCTROW Orders.OrderID, Orders.CustomerID, Orders.EmployeeID, Customers.FirstName, Customers.LastName, Orders.OrderDate, Orders.ShipDate, Orders.FreightCharge, Orders.ShipName, Orders.ShipAddress, Orders.ShipCity, Orders.ShipStateOrProvince, Orders.ShipZIPCode, Orders.ShipCountry, Customers.CompanyName, Customers.BillingAddress, Customers.City, Customers.StateOrProvince, Customers.ZIPCode, Customers.Country, Customers.ContactTitle, Orders.ShipPhoneNumber, Orders.ShipFaxNumber, Orders.PurchaseOrderNumber, Customers.Notes FROM Customers INNER JOIN Orders ON Customers.CustomerID = Orders.CustomerID;
What happens is when a new customer is selected, the cursor skips the first three controls and jumps to the 4th (the first 3 are , firstname, lastname, customerid). Those fields match the row query for selecting a customer i
Expand|Select|Wrap|Line Numbers
  1. SELECT Customers.CustomerID, [FirstName] & " " & [LastName] FROM Customers ORDER BY [FirstName] & "," & [LastName]; 
n the combo box:

This same combo box has also an AfterUpdate event:
Expand|Select|Wrap|Line Numbers
  1. Private Sub custname_AfterUpdate()
  2. Private Sub custname_AfterUpdate()
  3. Me.FilterOn = True
  4. Me.Filter = "CustomerID = " & Me.custname
  5. Me.Requery
  6. End Sub
  7.  

I think I need a Where statement that will allow me to bring up a customer when there isn't a prior order associated. Can anyone help me formulate one? Or if I'm wrong on my assumption, point me in the right direction. I tried a left join instead and it didn't work. thanks in advance

Rosie
Aug 25 '07 #1
9 1530
imrosie
222 100+
After reading my post I want to make clear the set up for the Main form. It has a subform to capture OrdersDetails(quantity, unit, price,,ect. and Products info) . But the controls on the main form capture data for the Orders table (such as Orders subtotal, Orders total, Order date, ect) and for the Customer tables (Customer name, Shipping details, etc.). Both get updated through that query for main form.

thanks
Rosie
Aug 25 '07 #2
Scott Price
1,384 Expert 1GB
Good morning Rosie!

You can try exploring a right or left join between your two tables in the original select query. Open the query in design view, double click on the line representing the join, it will bring up a dialog box with three options. Choose the one that says Show ALL records from table Customer and only those records from table Orders where the joined fields match (off the top of my head, here so the exact wording there might vary.)

There are a few ? marks in your code, but if it's working fine for you as is, I'll not bring them up :-)

Regards,
Scott
Aug 25 '07 #3
imrosie
222 100+
Good morning Rosie!

You can try exploring a right or left join between your two tables in the original select query. Open the query in design view, double click on the line representing the join, it will bring up a dialog box with three options. Choose the one that says Show ALL records from table Customer and only those records from table Orders where the joined fields match (off the top of my head, here so the exact wording there might vary.)

There are a few ? marks in your code, but if it's working fine for you as is, I'll not bring them up :-)

Regards,
Scott
Scott,

Hello and thanks for your comments....I continued trying to figure out why my left join didn't work....well I figured it out and now this is working great...

What happened was that I had the CustomerID coming from the Order table...I don't know how I kept overlooking that. Anyway, its working.
take care
Rosie
Aug 26 '07 #4
Scott Price
1,384 Expert 1GB
Glad to hear it's working for you, Rosie, and thanks for posting back with what you did to make it work!

Regards,
Scott
Aug 26 '07 #5
imrosie
222 100+
Glad to hear it's working for you, Rosie, and thanks for posting back with what you did to make it work!

Regards,
Scott
Hi Scott,

You're welcome.....I've noticed now I have a bit of a problem though. Since my Left Join is working beautifully, it's has broken two other features on my form.
1.) The control for OrderID (Orders) based on an autonumber too (it's part of the right side table of the Left Join), won't give me an Autonumber when I search a customer for the start of a new Order. Before (with Original Query) I would automatically get a new Autonumber (used for OrderID) in that control for the customer name in the combo box.

2.)I have a command button on the Form called "beginanorder". It's purpose was to retain customer information, while clearing old order info. When a customer was located through combo box, the old Order also populates the controls, so this command button worked like this:
Expand|Select|Wrap|Line Numbers
  1. Private Sub beginanorder_Click()
  2. 'Copies fields from original record to variables
  3. Field1 = Me.custacct
  4. Field2 = Me.atitle
  5. Field3 = Me.fname
  6. Field4 = Me.lname
  7. Field5 = Me.TheCompany
  8.  
  9. 'Begins a new record
  10. DoCmd.GoToRecord , , acNewRec
  11.  
  12. 'Plugs in old values into the new record
  13. Me.custacct.Value = Field1
  14. Me.atitle.Value = Field2
  15. Me.fname.Value = Field3
  16. Me.lname.Value = Field4
  17. Me.TheCompany.Value = Field5
  18. End Sub
  19.  
I could really use some great ideas on this one....I'm diligently trying to figure this one out. thanks so much
Rosie
Aug 27 '07 #6
Scott Price
1,384 Expert 1GB
Are we talking about the main form now, or the subform?

What is your subform based on and what does it display?

In my mind (correct me if I'm wrong, since I sometimes make unwarranted assumptions): I see your main form having Customer information, I see your subform having Order information. The two will be joined by a common CustomerID control. (seance quality narrative here, eh? :-) Main form is based on the Left-joined query that brings up all customer information, and subform is based on separate query that brings up the order information.

How am I doing so far?

Basing them both on the same query won't work for the reasons that you are experiencing.

As for the second problem you mentioned, you didn't say what it was doing wrong? An error message?

Regards,
Scott
Aug 27 '07 #7
imrosie
222 100+
Are we talking about the main form now, or the subform?

What is your subform based on and what does it display?

In my mind (correct me if I'm wrong, since I sometimes make unwarranted assumptions): I see your main form having Customer information, I see your subform having Order information. The two will be joined by a common CustomerID control. (seance quality narrative here, eh? :-) Main form is based on the Left-joined query that brings up all customer information, and subform is based on separate query that brings up the order information.

Errors:
On 1.) I simply get the Customer information, but no Orders info, such as that "OrderID" which is based on an autonum.

On 2.) Once I bring up a particu;lar customer, I click the "beginanorder" to clear out an Old order. I get this msg:
Error '2448', you can't assign a value to this object. It's referring to line number 13 in the code above for cmd(click) "beginanorder".

From what you've said so far Scott, it sounds like you're suggesting I figure out how to make the subform do Orders and Order Details??!.Is this right? (How am I doing?)

Rosie

How am I doing so far?

Basing them both on the same query won't work for the reasons that you are experiencing.

As for the second problem you mentioned, you didn't say what it was doing wrong? An error message?

Regards,
Scott
Yes Scott, we're talking Main Orders form here. Yes, it has the Customer information. It is now based on the 'left-joined query (qryOrdersSource) that includes the Customer and Orders fields. Yes, these tables are joined by the "CustomerID".

My subform within the Main Orders form is called "Orders Detail Subform". It is based on the "Orders Details" table (not a query). This table contains the fields; productid, quantity, unitprice, discount, orderid. It displays the dropdown list with products to choose, shows the quantity selected, discount, unitprice and extended price.
Aug 28 '07 #8
Scott Price
1,384 Expert 1GB
Yes Scott, we're talking Main Orders form here. Yes, it has the Customer information. It is now based on the 'left-joined query (qryOrdersSource) that includes the Customer and Orders fields. Yes, these tables are joined by the "CustomerID".

My subform within the Main Orders form is called "Orders Detail Subform". It is based on the "Orders Details" table (not a query). This table contains the fields; productid, quantity, unitprice, discount, orderid. It displays the dropdown list with products to choose, shows the quantity selected, discount, unitprice and extended price.
Unfortunately when one query is referring to a particular table, it will not be accessible by another query or form. So what is happening with your situation (my reading of it at the moment, anyway) is that when you open your main form query, it is accessing and thereby 'locking' the table that your subform is based on... Until you release the lock, you cannot make some (or maybe any) changes to it's data from outside of the query that is accessing it.

One solution, as you guessed above, is that your main form be used to display ONLY customer information, and your subform ONLY order information. This will allow you to isolate the two sources and should alleviate the problem of the write conflict you are experiencing with prob #2, and the related problem #1.

If you must refer to customer information on the orders subform, there are some ways we can explore to work around that, but I think you should be able to design the thing so you don't have to.

Let me know how it turns out.

Regards,
Scott
Aug 28 '07 #9
imrosie
222 100+
Unfortunately when one query is referring to a particular table, it will not be accessible by another query or form. So what is happening with your situation (my reading of it at the moment, anyway) is that when you open your main form query, it is accessing and thereby 'locking' the table that your subform is based on... Until you release the lock, you cannot make some (or maybe any) changes to it's data from outside of the query that is accessing it.

One solution, as you guessed above, is that your main form be used to display ONLY customer information, and your subform ONLY order information. This will allow you to isolate the two sources and should alleviate the problem of the write conflict you are experiencing with prob #2, and the related problem #1.

If you must refer to customer information on the orders subform, there are some ways we can explore to work around that, but I think you should be able to design the thing so you don't have to.

Let me know how it turns out.

Regards,
Scott
Scott, hi

I'll post back when I get things scrambled around on this main form. thanks for your insight
Rosie
Aug 28 '07 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Bryan Feeney | last post by:
I'm working on a site which dynamically generates tables of rates in CSV format. The script which does the work is called generate_stats.php. Here's the header header ("Content-type:...
5
by: Muhd | last post by:
Hey all, I have a basic table that looks something like this. CREATE TABLE MyTable ( ID INT IDENTITY PRIMARY KEY, Company_ID INT NOT NULL, Round VARCHAR(50) NOT NULL, Details VARCHAR(250)...
10
by: Jack | last post by:
Hi, I cannot get the date format correctly in dynamic sql statement, after trying various ways of handling it. I need some help with the date format in the following dynamic sql statement. Any...
1
by: Terencetrent | last post by:
I am trying to format a query expression drawn from a dialog box as percent. The original statement to get the value for the query is as follows: New%markup: !! The dialog box looks the...
9
by: nsj | last post by:
I am working with a web applicaction that accesses a SQL Server database. I need the value of the 'id' column of the last inserted row in the table 'PERSON'. The SQL statement for that purpose is:...
5
by: jeff | last post by:
i have written a program with date format as m/d/yyyy when i deploy it to client's machine, due to the client use d/m/yyyy format the Select SQL statement return some record wrongly. how can i...
2
by: troddy | last post by:
I am using the DatePart funtion in a query to extract the day, month and year in separate fields in a query. The function works fine but I am only getting a number for the month even if the field...
2
by: Billy | last post by:
This string is supposed to provide all records from an MDB database that match the courier and date specified in the query. I Response.Write the query and I get a date as 1/27/2007. The date...
3
by: inglesp | last post by:
Hi everyone I've come across some perculiar behaviour in a little database app I'm making with Access. I have a form for users to create a filter for data that goes into a cross-tab query. One...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.