Relating Values In Other Tables

egyptian_prince

Registered User.
Local time
Today, 18:30
Joined
Dec 6, 2003
Messages
14
Values relating in other tables!please read.....

i have a tblBooking.DateOfOrder and i want to make the date in this field not exceed the date in tblOuting.DateOfOuting

ive tried:

tblBooking.DateOfOrder<tblOuting.DateOfOuting


The second one is that i have created the database, with a tblCoachDetails and within that table there is a field called NumberOfSeatsAvailable, and what i want to do is with this is to make sure that when orders are placed, is that i dont want there to be more booked seats (tblBooking.NumberOfSeats) than avaliable.

can u help?

:confused:
 
Last edited:
Question #1: It sounds like your database structure may be bad. What is the relationship of tblBooking to tblOuting? If they both refer to like excursions then DateOfOuting should be in the same table/record of DateOfOrder.

Question #2: You can perform a query with a domain aggregate function to determine total number of seats taken for a particular expedition. Then compare that number to the new number of seats requested.

Both of these questions are rather indepth issues. If this "is urgent", you may want to reconsider your timeline.

HTH,
Jeff
 
The answer to the question 1 is that the relationship to the tblBooking and tblOuting is the OutingID is a primary key in tblOuting and a foreign key in tblBooking.

About question 2, im completely lost! can u be more specific because im new to access!

Thanks for the reply!

please get back in touch!

cheers!
 
1. To be clear, it would be helpful to me to list the fields in each table. From your answer, I assume that each "Outing" can have multiple "Bookings".

2. On your Booking form place a textbox (txtChairsFilled) that has its ControlSource equal to a DSum function. Look up DSum in the help file. Then use VBA to validate that the booking does not seat more than TotalSeats - txtChairsFilled.

-Jeff
 
Question 1: your assumption is correct. each outing has multiple bookings! would i have to change that in order for the dates to work?

Question 2: with your advice, i will put into practise now! and i will c how it goes! btw, i don't know VBA at all, im gonna learn that soon! ive got some books, what shall i read, for that DSum function?

get back to me asap!

cheers!

mo
 
1. The dates should work as I understand your structure now.

2. VBA is key to making anything but the most rudimentary databases. Welcome to your endeavor. DSum info is explained in the Help file. You will need to use an If...then...else construct in VBA in order to compare number of seats already assigned. A book (some are recommended on this site) is going to be the best way to learn VBA. When you hit a roadblock, post your (specific) questions to this forum.

HTH,
Jeff
 
in regards to question 1, what would i put in the validation field?

im trying:

=Date FROM tblOuting.DateOfOuting<Date IN tblBooking.DateOfOrder

but there's no joy! no joy at all!

get back to me please!

cheers!
 
First, you won't be comparing information in the tables directly. It is much easier to compare textboxes on forms based on the tables involved. When you get far enough into MS Access, you will find you can create direct comparisons of tables but that is much more involved.

If you are wishing to insure that the Date of Order is earlier than the Date of Outing, try this:

In the BeforeUpdate event of txtDateOfOrder put:

If DateValue(txtDateOfOrder)> DateValue(txtDateOfOuting) then
Msgbox "The order date must be earlier than the outing date."
Cancel = True 'This prohibits the entry and places the user back in the txtDateOfOrder textbox to correct his/her mistake.
End If


You will need to develop some error handling for the code above, because the user could type a nonsensical entry (such as "J@jk2Dk"), and this will crash the DateValue function.

HTH,
Jeff
 
hey jeff, right, ive tried that in the before update for txtDateOfOrder, but the problem is that it rejects all dates, even the correct ones! what do i do now?

:confused: :confused: :confused: :( :( :(
 
Looks like you have a bug in your code.

Try typing this in your Imediate Window:

If DateValue("3/3/64")>DateValue("4/12/76") then Print "Greater" else Print "Lesser"

If the above code works on your system then its your code that you need to debug.

-Jeff
 
No duplicate records!!!!!!!!!!!!

I have another enquiry!

how would i make sure that the same bookings cannot be booked twice?

so for example,

Mr John Smith cannot book a trip to Liverpool twice!!!


egyptian_prince
 
Your SQL will look something like this:

"SELECT fldName FROM tblBookings WHERE fldName = '" & txtName & "' AND fldOutingID = " & txtOutingID & ";"

If the recordcount is greater than 1, you know that it is a double booking and you can tell the user so.
 
so in theory, this would be typed in the validation rule properties section on the form or table design?

and secondly will it look like this:

SELECT DateOfOrder FROM tblBookings WHERE DateOfOuting = ' " & DateOfOrder & AND OutingID = & OutingID &

is that correct?

also could recommend any books on VB and SQL as i need to get into grips with them!!!!!

:confused:

cheers!
 
The SQL statement would be placed within the Before Update event of your txtName and txtDate on your frmBooking.

Note: It is good programming style (no, essential programming style) to use prefixes for tables, fields, queries, controls, etc... There are a number of suggested prefix lists out there, just pick one that you like. The utility of prefixes arises when trying to debug code. Your example...
SELECT DateOfOrder FROM tblBookings WHERE DateOfOuting = ' " & DateOfOrder & AND OutingID = & OutingID &
...is hard to decipher because I don't know if "DateOfOrder" is referring to a field or textbox.

Learning VBA is essential, and you really just have to bury your head in a book and look at a lot of sample code. There are many sample databases on this forum that you can study and pick apart.

This link suggests books that are worth your time:MS Access Books
I personally got a lot out of this book: Professional Visual Basic 6 Databases

My big time suggestion is to first develop your project as much as possible without incorporating any VBA. Create two tables (tblBookings and tblOutings) and a single form frmOuting with a subForm frmBooking. This simple database should be very functional to you even at this rudimentary level. Next, start adding short error trapping routines in VBA. An example would be "what if the user types a date that is in the past?". Finally, add more complicated error checking using VBA and SQL.

To get a taste of what VBA and SQL look like, here's a snippet from a project I'm working on:
Code:
Public Sub UpdateRecentList(lPatientID As Long)
Dim sSQL As String
Dim rsRecent As ADODB.Recordset
  sSQL = "SELECT fldUserID, fldPatientID, fldDate " & _
         "FROM tblUsersPatients " & _
         "WHERE fldUserID = " & Forms!frmSplashScreen!txtUserID & " " & _
         "ORDER BY fldDate;"
  Set rsRecent = New ADODB.Recordset: With rsRecent: .CursorType = adOpenStatic: .LockType = adLockPessimistic: .CursorLocation = adUseClient: .Open sSQL, CurrentProject.Connection
  .MoveFirst
  .Find "fldPatientID = " & lPatientID
  If .EOF Then 'If the PatientID is not in the list already...
    If .RecordCount < 10 Then
      .AddNew 'Create a new record if number of Recent PatientID's is not 10
    Else
      .MoveFirst 'Change the first record (oldest)
    End If
  End If
  !fldUserID = Forms!frmSplashScreen!txtUserID
  !fldPatientID = lPatientID
  !fldDate = Now()
  .Update
  .Close
  End With
  Set rsRecent = Nothing
  cmbRecent.Requery
  cmbRecent = cmbRecent.Column(0, 0)
End Sub

Its not easy. It's an educational process. But most importantly, it's just fun.

Good luck with your project.

-Jeff
 

Users who are viewing this thread

Back
Top Bottom