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

automatically insert data to another table by completing checkboxes

Hello everyone..

I'm on my way on creating a simple Database for a company. This database contains several tables, one of the tables will record information about the training that had been completed by each employee. There are about ten sections of training that should be completed.

Regarding to the database, I have two tables called 'Development' and 'CSA_Lisence'. 'Development' is the table that record the information about training which containing ten checkboxes (which represent ten sections of training) and CSA_Lisence will be automatically requeried when the checkboxes on Development are fully checked.

Here's the step I've been worked on :
First, I made a function called 'CheckCompletion' to ensure whether all the checkboxes are checked :
Expand|Select|Wrap|Line Numbers
  1. Public Function CheckCompletion() As Boolean
  2.  
  3.     Dim blnComplete As Boolean
  4.     Dim strCompletionSummary As String
  5.  
  6.     strCompletionSummary = Basic_Inspection & Certifying_Staff & Safety_Management_System & Regulation_Part_145 & Part_M & EWIS & Fuel_Tank_Safety_Level_2 & Dangerous_Goods & Human_Factor & Basic_Supervisory_Training
  7.  
  8.     If strCompletionSummary = "1111111111" Then
  9.         blnComplete = True
  10.     Else
  11.         blnComplete = False
  12.     End If
  13.  
  14. End Function
Second, I made a function called 'UpdateEmployee' to handles if all boxes are checked :
Expand|Select|Wrap|Line Numbers
  1. Public Function UpdateEmployee()
  2.  
  3.     Dim emp_numb As Long
  4.     Dim emp_name As Long
  5.     Dim strsql As String
  6.  
  7.     emp_numb = [Forms]![development].[employee_number].Value
  8.     emp_name = [Forms]![development].[employee_name].Value
  9.  
  10.    If CheckCompletion Then
  11.     strsql = "INSERT INTO CSA_Lisence (employee_number, employee_name) VALUES (" & emp_numb & " , " & emp_name & " )"
  12.     CurrentDb.Execute strsql
  13.    End If
  14. End Function
  15.  
then, i put this code on every checkbox's after update event (example only) :
Expand|Select|Wrap|Line Numbers
  1. Private Sub Basic_Inspection_AfterUpdate()
  2. Call UpdateEmployee
  3. End Sub
The problem is, nothing happened with the tables. However, when I managed to remove the 'If checkCompletion' condition, it worked and the 'CSA_Lisence' is requeried, but I will have ten multiple records with same contents (I just need one record per employee). I guess there's something wrong or missed in my code. Or i need to remove something? Any help would be appreciated. Thank you!

-deamond-
Jun 2 '15 #1
4 1489
jforbes
1,107 Expert 1GB
The first thing I see is that CheckCompletion will never return anything other than False as the output is never set. You could try this:
Expand|Select|Wrap|Line Numbers
  1. Public Function CheckCompletion() As Boolean 
  2.  
  3.     Dim strCompletionSummary As String
  4.  
  5.     strCompletionSummary = Basic_Inspection & Certifying_Staff & Safety_Management_System & Regulation_Part_145 & Part_M & EWIS & Fuel_Tank_Safety_Level_2 & Dangerous_Goods & Human_Factor & Basic_Supervisory_Training
  6.  
  7.     CheckCompletion = (strCompletionSummary = "1111111111") 
  8.  
  9. End Function
  10.  
Second, I would put a check in before inserting the Record to see if the Record already exists so that the Duplicate Record Situation doesn't happen:
Expand|Select|Wrap|Line Numbers
  1. Public Function UpdateEmployee()
  2.  
  3.      Dim emp_numb As Long
  4.      Dim emp_name As Long
  5.      Dim strsql As String
  6.  
  7.      emp_numb = [Forms]![development].[employee_number].Value
  8.      emp_name = [Forms]![development].[employee_name].Value
  9.  
  10.     If CheckCompletion Then
  11.         strsql  = "employee_number=" & emp_numb
  12.         If DCount("employee_number", "CSA_Lisence", strsql) = 0 Then
  13.             strsql = "INSERT INTO CSA_Lisence (employee_number, employee_name) VALUES (" & emp_numb & " , " & emp_name & " )"
  14.             CurrentDb.Execute strsql
  15.         End If
  16.     End If
  17.  End Function
Jun 2 '15 #2
jforbes
1,107 Expert 1GB
Also, for grins, you might try this instead:
Expand|Select|Wrap|Line Numbers
  1. Public Function CheckCompletion() As Boolean 
  2.     CheckCompletion = True
  3.     CheckCompletion = CheckCompletion AND Basic_Inspection
  4.     CheckCompletion = CheckCompletion AND Certifying_Staff
  5.     CheckCompletion = CheckCompletion AND Safety_Management_System
  6.     CheckCompletion = CheckCompletion AND Regulation_Part_145 
  7.     CheckCompletion = CheckCompletion AND Part_M
  8.     CheckCompletion = CheckCompletion AND EWIS
  9.     CheckCompletion = CheckCompletion AND Fuel_Tank_Safety_Level_2
  10.     CheckCompletion = CheckCompletion AND Dangerous_Goods
  11.     CheckCompletion = CheckCompletion AND Human_Factor
  12.     CheckCompletion = CheckCompletion AND Basic_Supervisory_Training 
  13. End Function
Jun 2 '15 #3
thank you for your answer, jforbes.
it's still hasn't worked for me, I guess I'm still missing something.
Anyway, regarding to the latest code you sent yesterday, where should I put the condition whether the checkboxes is checked or not? I mean, should I just put the code just like that or add some line instead? thank you...
Jun 3 '15 #4
jforbes
1,107 Expert 1GB
OK, So what is not working? Are you getting an error? Have you debugged your code to see what it is doing?

You don't have to use what is posted in Post #3 and it might be easier to get your code working first. It was just an example of another way of testing multiple Boolean values that I thought might be easier for you to read. To use it, it would be a direct replacement for you CheckCompletion function.
Jun 3 '15 #5

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

Similar topics

7
by: underground | last post by:
I wonder if possible on page load to query the value of a specific colmn and insert the result into another table. My query looks like so <? include("include/session.php"); ?> <? $usr =...
0
by: troydixon | last post by:
Hello, I am new at this, and have been trying to insert data into a table by using the footer of a gridview (which I dont like) or by using a detials view on the same page that is doing the...
1
by: boss1 | last post by:
hi all, i m new in php.i have a problem that is i m using a php form where i can retrieve one field value from one table in oracle db by ajax and its working properly. but i need to insert the...
1
by: cathycros | last post by:
Hi, I'm trying to take data from varchar fields in one table and copy it to Nvarchar fields in another table. (Long story - now dealing with multiple languages, not enough space in row in current...
17
by: msmjsuarez | last post by:
Hello, I need help... How to automatically insert data to mysql database without submit button using php? Is there a way on this? thanks a lot.
2
by: pavelcc | last post by:
I need to insert data into a table after validating that the data doesn't already exist on the table. In addition to that I need to update data if there are any changes. I got the insert part...
1
by: lipali prusty | last post by:
the procedure should take the table name as input from argument.and data will be inserted to the table mentioned in the argument list
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
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
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,...
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...

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.