473,320 Members | 1,946 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,320 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 1486
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: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.