473,471 Members | 4,648 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Update Query? *Headache*

5 New Member
Hi there everyone, new here but after reading around it seems like I might hang about - so many helpful threads!

I have a slight problem. This flying club near me has employed me to make them a database.
I got into it because I know one of the guys who works there, and he mentioned they need one and I did Computing A level a few years back so I thought it would be a doddle and some much needed cash!

Well it's a headache :(

It's essentially a booking system. The problem is each flight you book has a start time and an end time which you can pick.
I have it set out on a form and it's working great, up to this point which is where you need to select a plane.

I am dealing with two types of planes - a Cessna and a piper. So after picking a date for the booking and the start and end times you select the type of plane in a list box.

I then have another listbox which I want to show which planes under that category (piper or Cessna) are not booked on the selected date and between the selected times.

So that's what I would like. Now the rest of this is me failing to manage it.

My idea was to put a flag in the table of planes, and then run an update query on the flag to mark planes which were available.

So I am using my bookings table, and the list of planes table to run this query.

In my head, I see the criteria as :
• Booked date is equal to selected date
• Plane type is equal to selected plane type
• Flag is to be updated to "yes"
• BookedStartTime is greater than EndTime AND BookedEndTime is less than StartTime.

In my head that should work. The last bullet point will only select planes which are not already booked out at the selected times, the top bullet point will make sure I am only looking at bookings on the right day etc.

The problem is when it runs it updates the wrong things. It kind of half works.
The biggest problem is that it is also not showing planes which have no bookings that day, only planes which have bookings that day, but ones which are free at the selected time.

I am not sure how I would type the last bullet point in.

SQL View of it:
UPDATE tblPlane INNER JOIN tblBookings ON tblPlane.PlaneID = tblBookings.PlaneID SET tblPlane.Flag = Yes
WHERE (((tblBookings.[Time Start])>=[Forms]![frmMakeBooking]![cboEndTime]) AND ((tblBookings.[Time Finish])>=[Forms]![frmMakeBooking]![cboStartTime]) AND ((tblBookings.Date)=[Forms]![frmMakeBooking]![txtSelectedDate]));


Any help, guidance or just a pointer in the right direction would be really gratefully received.
Thanks.
Mar 27 '07 #1
9 1690
MMcCarthy
14,534 Recognized Expert Moderator MVP
First forget about the UPDATE query. You can do this with cascading combo boxes. More details on this can be found in this tutorial.

Cascading Combo/List Boxes


Now we just need to work out the Row Source for the second combobox. The following query should only return Planes available during the booking time and date.

Expand|Select|Wrap|Line Numbers
  1. SELECT tblPlane.* 
  2. FROM tblPlane
  3. WHERE PlaneID NOT IN
  4. (SELECT PlaneID FROM tblBookings
  5. WHERE (((([Time Start])<=[Forms]![frmMakeBooking]![cboStartTime]
  6. AND [Time Finish])>=[Forms]![frmMakeBooking]![cboStartTime]))
  7. OR (([Time Start])<=[Forms]![frmMakeBooking]![cboEndTime]
  8. AND [Time Finish])>=[Forms]![frmMakeBooking]![cboEndTime])))
  9. AND (tblBookings.Date)=[Forms]![frmMakeBooking]![txtSelectedDate])));
  10.  
Mary
Mar 27 '07 #2
pandaking
5 New Member
Wow Mary - thanks for the speedy and very helpful response!
I am trying to work out how to do the combo boxes now, but when I enter that code into the sql view of a query it says:

"Extra ) in query expression 'PlaneID NOT IN ..............' "

I have had a look through it myself to see what it is talking about but to be honest I have no idea what I am doing :p

Thanks again for the fantastic reply.
Mar 27 '07 #3
MMcCarthy
14,534 Recognized Expert Moderator MVP
OK, try this ...

Expand|Select|Wrap|Line Numbers
  1. SELECT tblPlane.* 
  2. FROM tblPlane
  3. WHERE PlaneID NOT IN
  4. (SELECT PlaneID FROM tblBookings
  5. WHERE (((([Time Start]<=[Forms]![frmMakeBooking]![cboStartTime]
  6. AND [Time Finish]>=[Forms]![frmMakeBooking]![cboStartTime]))
  7. OR (([Time Start]<=[Forms]![frmMakeBooking]![cboEndTime]
  8. AND [Time Finish]>=[Forms]![frmMakeBooking]![cboEndTime])))
  9. AND (tblBookings.Date=[Forms]![frmMakeBooking]![txtSelectedDate])));
  10.  
By the way you may have to add a criteria to this. Something like
Expand|Select|Wrap|Line Numbers
  1. AND (tblBookings.Date=[Forms]![frmMakeBooking]![txtSelectedDate])
  2. AND (PlaneType=[Forms]![frmMakeBooking]![comboboxName])));
Mary
Mar 27 '07 #4
pandaking
5 New Member
Sorry I am not quite following where the criteria go, just in any of the criteria boxes of the query? Or a certain one?

Do I just switch the query I made with that main block of code to design view and paste the criteria code in that?

Thanks again for your super support :)
Mar 27 '07 #5
MMcCarthy
14,534 Recognized Expert Moderator MVP
This would actually go in the Row Source for your second combo box.

Expand|Select|Wrap|Line Numbers
  1. SELECT tblPlane.* 
  2. FROM tblPlane
  3. WHERE PlaneID NOT IN
  4. (SELECT PlaneID FROM tblBookings
  5. WHERE (((([Time Start]<=[Forms]![frmMakeBooking]![cboStartTime]
  6. AND [Time Finish]>=[Forms]![frmMakeBooking]![cboStartTime]))
  7. OR (([Time Start]<=[Forms]![frmMakeBooking]![cboEndTime]
  8. AND [Time Finish]>=[Forms]![frmMakeBooking]![cboEndTime])))
  9. AND (tblBookings.Date=[Forms]![frmMakeBooking]![txtSelectedDate])))
  10. AND (PlaneType=[Forms]![frmMakeBooking]![comboboxName]);
  11.  
Make sure to change PlaneType to the name of the field in tblPlane and comboboxName to the name of the first combobox.

Mary
Mar 27 '07 #6
pandaking
5 New Member
That code you just gave me for the row source is perfect! Works like a dream :D
I don't know quite what to say, thank you would be a good start I guess.

I just need to work out how to refresh that second combo box (and the row source query), so that when I select a different time or a different plane type it updates itself :p
Mar 29 '07 #7
MMcCarthy
14,534 Recognized Expert Moderator MVP
That code you just gave me for the row source is perfect! Works like a dream :D
I don't know quite what to say, thank you would be a good start I guess.

I just need to work out how to refresh that second combo box (and the row source query), so that when I select a different time or a different plane type it updates itself :p
You're welcome.

To requery the second combobox you will need to add an After Update event to the first combobox.
Expand|Select|Wrap|Line Numbers
  1. Private Sub FirstComboBox_AfterUpdate()
  2.    Me!SecondCombobox.Requery
  3. End Sub
  4.  
Mary
Mar 29 '07 #8
pandaking
5 New Member
You star!
Thanks again for everything :)
Mar 29 '07 #9
MMcCarthy
14,534 Recognized Expert Moderator MVP
You star!
Thanks again for everything :)
No problem ;)
Mar 29 '07 #10

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

Similar topics

4
by: Surendra | last post by:
I have this query that I need to use in an Update statement to populate a field in the table by the value of Sq ---------------------------------------------------------------------------- Inline...
1
by: Ryan | last post by:
Hello, I have a quick question (I hope). I have a form with a combo box and a multi-selection list box. The list box is based on a query. Users can select values from the cmbobox to add to...
8
by: Maxi | last post by:
There is a lotto system which picks 21 numbers every day out of 80 numbers. I have a table (name:Lotto) with 22 fields (name:Date,P1,P2....P21) Here is the structure and sample data: ...
7
by: Mark Carlyle via AccessMonster.com | last post by:
I have this update query that I am trying to run. I know the syntax is messed up but do not know how to correct it. Select 'UPDATE', Transactions,'Set = where = ' From "Get Daily Balances" ...
1
by: Tim Nelson | last post by:
I am coming from a ESQL/C environment and I have the need to create an application that builds an insert and an update statement dynamically by querying a the schema for a database table. With...
15
by: Darren | last post by:
Help, i want to run an update query from a form.. and was wonderin.. Can the update query run if i want to update a value manually inputted from a form (e.g. !!) to a table...
1
by: jgreve | last post by:
(aix 5.1, db2 8.1.6) Consider this toy example: -------------------- create table foo ( alpha int, beta int ); insert into foo ( 100, -1 ); insert into foo ( 200, -1 ); insert into foo (...
0
by: MIHAB | last post by:
Hi everyone. I have experienced a weird type of error – something obvious but I can’t get it. I am working with the ASP (VBSCRIPT) and FoxPro tables via ODBC. The goal is to update one table...
16
by: ARC | last post by:
Hello all, So I'm knee deep in this import utility program, and am coming up with all sorts of "gotcha's!". 1st off. On a "Find Duplicates Query", does anyone have a good solution for...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.