Connecting Tech Pros Worldwide Help | Site Map
Reply
 
LinkBack Thread Tools Search this Thread
  #1  
Old July 3rd, 2008, 04:01 PM
Member
 
Join Date: Dec 2007
Posts: 46
Default Update Statments

Hi All
Please help me .Hope i have described my problem clearly below.
I have a condition where i need to update some data in table from the value taken from another table.So basically i need to create a update statment to perform the data manipulation.but i am not able to write the update statments.I have two tables..Tab_Bookings and tab_Booking_Fare_Lines .Both are joined by field Booking_ID.Now there is a column No_Passengers in Tab_Booking and there is a column called Number_of_Passengers in Tab_Booking_child.Now i want a update statment which will update No_of_Pass_Type_1 column in Tab_Booking table from
tab_Booking_Fare_Lines for each booking_ID.Thanks in advance.The main problem for me here is that data is in one to many data.so i need to take the Sum([tab_Booking_Fare_Lines].[Number_of_Passengers])
I have written a update statements but its creating an error for me which says "You tried to execute a query that doesnot inclue expression No_of_Pass_Type_1 as part of aggregate function.

Thanks in advance

Expand|Select|Wrap|Line Numbers
  1.  
  2. UPDATE tab_Bookings INNER JOIN tab_Booking_Fare_Lines ON tab_Bookings.File_No = tab_Booking_Fare_Lines.Booking_Id SET tab_Bookings.No_of_Pass_Type_1 = Sum([tab_Booking_Fare_Lines].[Number_of_Passengers])
  3.  
  4.  
Reply
  #2  
Old July 3rd, 2008, 06:11 PM
ADezii's Avatar
Expert
 
Join Date: Apr 2006
Location: Philadelphia
Age: 59
Posts: 4,338
Default

Your description of the problem is a little confusing and contradictory, but it can be solved in the following manner. I'm sure there is a SQL answer, but right now it elludes me.
Expand|Select|Wrap|Line Numbers
  1. Dim MyDB As DAO.Database
  2. Dim MyRS As DAO.Recordset
  3. Dim lngTotalPassengers As Long
  4.  
  5. Set MyDB = CurrentDb()
  6. Set MyRS = MyDB.OpenRecordset("Tab_Bookings", dbOpenDynaset)
  7.  
  8. Do While Not MyRS.EOF
  9.   lngTotalPassengers = Nz(DSum("Number_Of_Passengers", "Tab_Booking_Fare_Lines", _
  10.                                "[Booking_ID] = " & MyRS![Booking_ID]), 0)
  11.     MyRS.Edit
  12.       MyRS![No_Passengers] = lngTotalPassengers
  13.     MyRS.Update
  14.   MyRS.MoveNext
  15. Loop
  16.  
  17. MyRS.Close
  18. Set MyRS = Nothing
Reply
  #3  
Old July 4th, 2008, 04:01 PM
Member
 
Join Date: Dec 2007
Posts: 46
Default

Hi

Thanks for VBA code.If you find sql query and if you have time then do please post it.


Quote:
Originally Posted by ADezii
Your description of the problem is a little confusing and contradictory, but it can be solved in the following manner. I'm sure there is a SQL answer, but right now it elludes me.
Expand|Select|Wrap|Line Numbers
  1. Dim MyDB As DAO.Database
  2. Dim MyRS As DAO.Recordset
  3. Dim lngTotalPassengers As Long
  4.  
  5. Set MyDB = CurrentDb()
  6. Set MyRS = MyDB.OpenRecordset("Tab_Bookings", dbOpenDynaset)
  7.  
  8. Do While Not MyRS.EOF
  9.   lngTotalPassengers = Nz(DSum("Number_Of_Passengers", "Tab_Booking_Fare_Lines", _
  10.                                "[Booking_ID] = " & MyRS![Booking_ID]), 0)
  11.     MyRS.Edit
  12.       MyRS![No_Passengers] = lngTotalPassengers
  13.     MyRS.Update
  14.   MyRS.MoveNext
  15. Loop
  16.  
  17. MyRS.Close
  18. Set MyRS = Nothing
Reply
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 205,248 network members.