473,756 Members | 7,560 Online
Bytes | Software Development & Data Engineering Community
+ 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.PlaneI D = tblBookings.Pla neID SET tblPlane.Flag = Yes
WHERE (((tblBookings.[Time Start])>=[Forms]![frmMakeBooking]![cboEndTime]) AND ((tblBookings.[Time Finish])>=[Forms]![frmMakeBooking]![cboStartTime]) AND ((tblBookings.D ate)=[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 1704
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
10237
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 View Query: Select Sq from ( Select substr(to_date(End_Date,"DD-MON-YYYY"),4), End_Date, Rank() Over (Partition by substr(to_date(End_Date,"DD-MON-YYYY"),4) Order by End_Date) As Sq
1
3336
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 the list box (items they wish inserted into the table), or they can select items in the list box to delete (from the table). Once they have finished making any changes, they are to click a SAVE button to actually commit the changes to the database....
8
3724
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: "Date","P1","P2","P3","P4","P5","P6","P7","P8","P9","P10","P11","P12","P13","P14","P15","P16","P17","P18","P19","P20","P21" 1/1/2005,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21 1/2/2005,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22
7
3535
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" Transactions = name of the table I want to update balance = name of the field i want to update daily balance= name of the query result that I want to move to the table
1
3236
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 .Net it seems there are too many tools to work with. Basically, the application takes 3 parameters: 1. A database connection string 2. A table name 3. An import file of pipe-delimited records
15
3306
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 (tblPasswordMgmt.Password) but based on a criteria which is neither the two values. Instead it's like (!!=tblPasswordMgmt.UserID).
1
1845
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 ( 300, -1 );
0
1125
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 using records from another(same structure). The task works perfectly on the small table (300 – 400 records) but giving me the headache with the 6000+ records. Sometimes code works like a charm (on LOCALHOST majority of the time) but most frequently it...
16
3516
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 renaming the duplicate records? My thinking was to take the results of the duplicate query, and somehow have it number each line where there is a duplicate (tried a groups query, but "count" won't work), then do an update query to change the duplicate to...
0
9462
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9287
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10046
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9886
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9857
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9722
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8723
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7259
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5318
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.