473,396 Members | 1,866 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,396 software developers and data experts.

Insert into statement only completing once

BenRatcliffe
Hi there,

I was wondering if anyone could help me. I have a comlpex database with a number of forms that have data entered on them and then saved into the correct table etc. In this instance I am trying to get the data on a form to save the data in the current table where it is stored, insert the data into 2 new tables all on a click event. I have got the first 2 tables to update fine but the third I am having difficulty with.

The third table records all action, like a snapshot view of what is happening in the database. It records data when a training course is authorised and cancelled with the date it was done and the change in budget.

The problem i'm having is that the third table will update once but will not insert any more records unless that one record is deleted. I have used the insert into statement throughout the database with no problems to date but i can't seem to figure this out.

Any pointers would be a great help.

Sorry about lack of commenting its still in development stage!

Expand|Select|Wrap|Line Numbers
  1. Private Sub btn_accept_Click()
  2.  
  3. On Error GoTo Err_btn_accept_Click
  4.  
  5. DoCmd.SetWarnings off
  6.  
  7. Forms!FRM_PRE_BOOK_MANAGER!FRM_BUDGET.Form.RecordSource = ("SELECT LU_BUDGET.Year, LU_BUDGET.[Start Date], LU_BUDGET.[End Date], LU_BUDGET.Budget FROM LU_BUDGET WHERE (((LU_BUDGET.[Start Date])<[Forms]![FRM_PRE_BOOK_MANAGER]![Date_to_attend]) AND ((LU_BUDGET.[End Date])>[Forms]![FRM_PRE_BOOK_MANAGER]![Date_to_attend]));")
  8.  
  9. txt_budget = Me.FRM_BUDGET!budget - Me.Cost
  10.  
  11. Me.FRM_BUDGET!budget = txt_budget
  12.  
  13. If IsNull(Training_Priority) Then
  14.  
  15. MsgBox ("Please enter a training priority")
  16.  
  17. ElseIf IsNull(Me.cmb_cost_code) Then
  18.  
  19. MsgBox ("Please enter a Cost Code")
  20.  
  21. Else
  22.  
  23. Me.Confirmed_date = Date
  24. Me.request_confirmed = "Yes"
  25.  
  26. DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
  27.  
  28. DoCmd.RunSQL ("INSERT INTO TBL_COURSE_BOOKINGS ( User_ID, Course_ID, Pre_Book_ID, Date_To_Attend, Duration, Cost, Location, Cost_Code )SELECT [Forms]![FRM_PRE_BOOK_MANAGER]![User_ID] AS Expr1, [Forms]![FRM_PRE_BOOK_MANAGER]![Course_ID] AS Expr2, [Forms]![FRM_PRE_BOOK_MANAGER]![Pre_Booking_ID] AS Expr3, [Forms]![FRM_PRE_BOOK_MANAGER]![Date_To_Attend] AS Expr4, [Forms]![FRM_PRE_BOOK_MANAGER]![Duration] AS Expr5, [Forms]![FRM_PRE_BOOK_MANAGER]![Cost] AS Expr6,[Forms]![FRM_PRE_BOOK_MANAGER]![Location] AS Expr7,[Forms]![FRM_PRE_BOOK_MANAGER]![Cost_Code] AS Expr8;")
  29.  
  30. DoCmd.RunSQL ("INSERT INTO TBL_RECENT_ACTIVITY ( User_ID, First_Name, Last_Name, Course_ID, Course_Title, Cost)Values ([Forms]![FRM_PRE_BOOK_MANAGER]![User_ID], [Forms]![FRM_PRE_BOOK_MANAGER]![First Name], [Forms]![FRM_PRE_BOOK_MANAGER]![Surname], [Forms]![FRM_PRE_BOOK_MANAGER]![Course_ID], [Forms]![FRM_PRE_BOOK_MANAGER]![Course Title], [Forms]![FRM_PRE_BOOK_MANAGER]![Cost])")
  31.  
  32. If Me.First_Name + " " + Me.Surname = Forms!frm_start_page!lst_first_name + " " + Forms!frm_start_page!lst_last_name Then
  33.  
  34.   GoTo save_record
  35.  
  36.   Else
  37.  
  38.     tempsubject = "Training Database - Your training request has been accepted, Ref: Course :- " + Me.Course_Title
  39.     tempbody = Forms!frm_start_page!lst_first_name + " " + Forms!frm_start_page!lst_last_name + " has accepted your training request"
  40.  
  41.       DoCmd.SendObject _
  42.     , _
  43.     , _
  44.     , _
  45.     Me.First_Name + " " + Me.Surname, _
  46.     Forms!frm_start_page!lst_first_name + " " + Forms!frm_start_page!lst_last_name, _
  47.     , _
  48.     tempsubject, _
  49.     tempbody, _
  50.     False
  51.  
  52.     End If
  53.  
  54.  
  55.  
  56. save_record:
  57.  
  58. MsgBox ("Course has been Confirmed")
  59.  
  60. If CurrentProject.AllForms("FRM_MAN_BOOK_REQ_TAB").IsLoaded Then
  61.  
  62. Forms!frm_man_book_req_tab.Form.Requery
  63.  
  64. End If
  65.  
  66. Forms!frm_start_page!FRM_DUE_COURSES.Form.Requery
  67.  
  68. DoCmd.Close acForm, "FRM_PRE_BOOK_STAFF"
  69. DoCmd.Close
  70.  
  71. End If
  72.  
  73. Exit_btn_accept_Click:
  74.     Exit Sub
  75.  
  76. Err_btn_accept_Click:
  77.     MsgBox Err.Description
  78.     Resume Exit_btn_accept_Click
  79. End Sub
by the way the 2nd insert statement is the one that is causing problems, I have tried it exactly the same as the first insert into (with the select instead of values) but to no effect!

Many thanks
Ben
Apr 7 '08 #1
0 1584

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

Similar topics

1
by: shottarum | last post by:
I currently have 2 tables as follows: CREATE TABLE . ( mhan8 int, mhac02 varchar(5), mhmot varchar(5), mhupmj int )
2
by: hartley_aaron | last post by:
Hi, I have an application running on a wireless device and being wireless I want it to use bandwidth as efficiently as possible. Therefore, I want the SQL statement that it uploads to the SQL...
3
by: Mark Morton | last post by:
I'm writing an if statement for a UK credit card form validation script. Users who specify that their card is Switch need to enter either the issue number or the 'valid from' date. I'm trying to...
10
by: Mike | last post by:
I know this sounds strange but I am at a loss. I am calling a simple funtion that opens a connection to a SQL Server 2000 database and executes an Insert Statement. private void...
14
by: Chris Ochs | last post by:
The documentation doesn't have any examples of using an sql language function to do an insert, andI am at loss as to I am doing wrong here. The error I get trying to create the function is: ERROR:...
2
by: Geoffrey KRETZ | last post by:
Hello, I'm wondering if the following behaviour is the correct one for PostGreSQL (7.4 on UNIX). I've a table temp_tab with 5 fields (f1,f2,f3,...),and I'm a launching the following request :...
3
by: mahajanvit | last post by:
Hi one and all I got this problem during my project. So in order to solve this I made a very small application. I am trying to insert using SP and sqldatasource control. I know that while using...
6
by: rn5a | last post by:
During registration, users are supposed to enter the following details: First Name, Last Name, EMail, UserName, Password, Confirm Password, Address, City, State, Country, Zip & Phone Number. I am...
3
by: tricard | last post by:
Good afternoon, I am having troubles with an insert into statement in Access 2002 that I am performing through VBA. I am inserting a single record into a table with one yes/no field. For some...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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,...

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.