473,405 Members | 2,261 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,405 software developers and data experts.

Complicated Query (or is it?)

Hi

I have another problem with my appointment booking database.

I have a table with available times, ranging from 8:00 to 17:00

When booking an appointment you select a time from a drop-down list (combo box), the source is therefore the table of times.

What I want is for the times that have already been taken (entered in the appointments table for that date) to not appear in the list, so that clashes are impossible as only the available times will be shown when booking a new appointment.

I’m sure this is possible with some kind of query but I just can’t work it out. Does anybody know how this would be accomplished? Or is this not possible?

Thanks.
Feb 17 '08 #1
7 1290
Scott Price
1,384 Expert 1GB
Without knowing the names of your field I will have to assume a few things, but this is the general form:
Expand|Select|Wrap|Line Numbers
  1. SELECT [FieldName], [FieldName2] FROM [Table] WHERE IsNull([BookedStatusField]) 
This will choose any available time where there is nothing entered in the field you have to record bookings.

Regards,
Scott
Feb 17 '08 #2
Hi, thanks for replying.

I'm not quite sure that I've got this set up in the way you think, I've probably set it up incorrectly. At the moment the Appointments form has a field that is the start time, this selects times from a separate table that only has one column (times). There is another field called appointment date.

What I was trying to do was somehow check all the appointments on the date selected in the appointment date field and so only display the times in the list from the times table that hadn't already been selected for other appointments.

I don't really understand VB, where would I have to enter that code so that the look up list would only contain the desired (vacant) start times?

Thanks a lot for your help.
Feb 17 '08 #3
sierra7
446 Expert 256MB
Hi

One solution to this would be to have a small table (lets call it tblSlots) that just listed the times of the appointment slots [SlotTime] (text for each hour, half hour or whatever) and an [ID] field (autonumber). Create this table and add as many slots as there are in a working day; they will number themselves from 1 to whatever.

On the Appointments table (lets call it tblApps) you should hold an integer field for the appointment time (it can look-up what the time is because you dont want to be writing hours and minutes etc)

Lets assume that the time slot field in tblApps is called [AppSlotID] and the date of the appointment is [AppDate]. The control Source for your combo-box would be;

Expand|Select|Wrap|Line Numbers
  1.  
  2. SELECT tblSlots.ID, tblSlots.SlotTime FROM tblSlots LEFT JOIN tblApps ON tblSlots.id = tblApps.AppSlotID WHERE (((tblApps.ApID) Is Null) AND ((tblApps.AppDate)=[AppDate]));
  3.  
The Column Count of your combo =2
The Column Widths = 0;2.54 so the first colum is hidden.

After you assign a date to the Appointment you will need to run a Requery on the combo box;-
Expand|Select|Wrap|Line Numbers
  1. Private Sub AppDate_AfterUpdate()
  2. Me!cmbSlots.Requery
  3. End Sub
When you then open the combo you should only see listed the 'slots' which are available.

S7
Feb 18 '08 #4
Scott Price
1,384 Expert 1GB
It sounds like you would benefit greatly from reading and understanding the concepts in this How-To article: Database Normalization and Table structures.

Please have a look and then examine your database structure to make sure you are complying with the rules called Normal Forms.

Once you have done so, you'll find that the sample query I mentioned earlier should take care of all your needs.

You might enjoy reading a good book on the subject of how to use Access as well. There are several very good ones out there, just make sure that it's at least 2 inches thick (not a joke :-)!

Kind regards,
Scott
Feb 18 '08 #5
FishVal
2,653 Expert 2GB
Hi, there.

You may take a look at a similar thread - Iif query.

Regards,
Fish
Feb 18 '08 #6
Thanks a lot for your help, I've got it working now.
Thanks again, I really appreciate it. :]
Feb 19 '08 #7
NeoPa
32,556 Expert Mod 16PB
A minor point, but when checking for Null values in SQL it's more efficient to use the form :
Expand|Select|Wrap|Line Numbers
  1. WHERE [X] Is Null
than the function calling form :
Expand|Select|Wrap|Line Numbers
  1. WHERE IsNull([X])
IE This is because the "Is Null" construct is within SQL itself and can be included in the optimising. A function call will always mean that each record needs to be processed even if it's later discarded.
Feb 22 '08 #8

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

Similar topics

3
by: Chris | last post by:
Hello all- Fairly new to SQL and I need to issue a pretty complex query (complex being a relative term here :) ). To dumb down my example for display purposes, I have two tables in my schema...
10
by: jqq | last post by:
SQL2K on W2Kserver I need some help revamping a rather complicated query. I've given the table and existing query information below. (FYI, changing the database structure is right out.) The...
5
by: Norma | last post by:
I am trying to make a query pull data from between the dates I enter in the parameter but also look back 'in time' to see where 2 other fields have null values, and only pull data into the query if...
4
by: d.p. | last post by:
I need to create a conditional expression that's not a simple one. I need the expression to be in the field of a table, that depends on another field (different column) in that same table. It...
26
by: Jeff | last post by:
Ok gang. Here is something complicated, well, at least to me anyway. Using Access DB I have a table in my DB called members. In that table, I have 2 tables I will be using "username" and...
4
by: Matthew Crouch | last post by:
i suck so much that i don't even know if this is a JOIN or a subquery or who-knows what. Here's the idea: I want to select two things at the same time (form one table) average for columnX and...
0
by: norm10115 | last post by:
I have a single MySQL table named "monthly" that contains the following fields: Id, Name, Interface, Status, MonYear I want to query "Status" for the past 3 months, of each "Device" and...
0
by: Nick | last post by:
Hi, I have two tables Trade table and Cons table. Records are inserted in both the tables independent of each other. There are fields like Exc_Ref, Qty, Date in both the tables. I need to...
7
by: MarkNeumann | last post by:
I'm coming from a Corel paradox background and moving into an Access environment. So I'm struggling with something that I think is probably way simpler than I'm making it out to be. Access 2007...
3
by: jonceramic | last post by:
Hi All, I need to know the best way to set up a datawarehouse/materialized view for doing statistics/graphs in Access. My crosstabs and unions are getting too complicated to crunch in real...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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...
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,...

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.