By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,716 Members | 1,296 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,716 IT Pros & Developers. It's quick & easy.

automatically insert data to another table by completing checkboxes

P: 6
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
Share this Question
Share on Google+
4 Replies


jforbes
Expert 100+
P: 1,107
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
Expert 100+
P: 1,107
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

P: 6
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
Expert 100+
P: 1,107
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

Post your reply

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