473,385 Members | 2,005 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,385 software developers and data experts.

Adding mutiple records to a table when adding a new record to another table

I have a table for employees and a table that shows which containers they have access to and a table of all containers.

What i need to do is when adding a new employee i need to add a record to the "access" table for each record in the container table. that would basically default the new employee's access to each container.

I think the following code in my addemployee form_Load event should detect if they have been added. but i'm having trouble with figureing out how to proceed on what needs to done.
Expand|Select|Wrap|Line Numbers
  1. Dim emp As String
  2. emp = "employee = " & Staffadd.ID
  3. If DLookup("[Containerstring]", "access", emp) = Null Then
the above code should only detect a null if there is not an entry for the employee in the "access" table

what i need help with is:

A) I don't know how to tell how many entreis are in the containers table.

and
B) I don't know how to programitacly add records to a table.

With this information i should be able to simply loop through the containers table and add a record to the access table for the new employee each record in the containers table.
Jun 9 '10 #1
2 1398
vb5prgrmr
305 Expert 100+
Time to use your friends (yahoo, google, ask, answers, bing) and search for vb6 ado tutorial. Then once you have absorbed that you can use these for your various questions.
Expand|Select|Wrap|Line Numbers
  1. strSQL = "INSERT INTO tblEmp(vFName, vLName, iNumericField, dDateField) VALUES('" & Text1.Text & "','" & Text2.Text & "'," & Text3.Text & ",#" & Text4.Text & "#)"
  2.  
  3. ?strSQL
  4. INSERT INTO tblEmp(vFName, vLName, iNumericField, dDateField) VALUES('John','Doe',3,#6/10/2010#)
  5.  
  6. 'Note: the date field surrounded by the pound sign (#) is an access thing while SQL Server will not accept a
  7. 'date surrounded by the pound sign but will accept a date surround by single ticks (') like the two varchar
  8. 'fields shown above ('John','Doe',...)
  9.  
  10. adoCn00.Execute strSQL
  11.  
  12. strSQL = "SELECT iEmpID FROM tblEMP WHERE vFName = '" & Text1.Text & "' AND vLName = '" & Text2.Text & "'"
  13.  
  14. adoRs00.Open strSQL, adoCn00,...
  15.  
  16. strSQL = "SELECT iConID, vConDesc FROM tblCon"
  17.  
  18. adoRs01.Open strSQL, adoCn00,...
  19.  
  20. Do While adoRs01.EOF = False
  21.   If adoRs01.Fields("vConDesc").Value = "Low" Then
  22.     strSQL = "INSERT INTO tblEmpConAccess(iEmpID, iConID, iAccessLevel) VALUES(" & adoRs00.Fields("iEmpID").Value & "," & adoRs01.Fields("iConID").Value & ",1)"
  23.   Else
  24.     strSQL = "INSERT INTO tblEmpConAccess(iEmpID, iConID, iAccessLevel) VALUES(" & adoRs00.Fields("iEmpID").Value & "," & adoRs01.Fields("iConID").Value & ",0)"
  25.   End If
  26.   adoCn00.Execute strSQL
  27.   adoRs01.MoveNext
  28. Loop
  29.  
  30. strSQL = SELECT COUNT(iEmpConAccessID) As AccCnt FROM tblEmpConAccess WHERE iEmpID = " adoRs00.Fields("iEmpID").Value
  31.  
  32. adoRs00.Close
  33. adoRs01.Close
  34. Set adoRs00 = New ADODB.Recordset
  35. Set adoRs01 = New ADODB.Recordset
  36.  
  37. adoRs00.Open strSQL, adoCn00,...
  38.  
  39. strSQL = SELECT COUNT(iConID) As ConCnt FROM tblCon
  40. adoRs01.Open strSQL, adoCn00,...
  41.  
  42. If adoRs00.Fields("AccCnt").Value <> adoRs01.Fields("ConCnt").Value Then
  43.   'problem as employee was not added to each container
  44.   'so need to correct somehow
  45. End If
  46.  
  47. adoRs00.Close
  48. adoRs01.Close
  49. Set adoRs00 = Nothing
  50. Set adoRs01 = Nothing
  51.  
or something like that...



Good Luck
Jun 10 '10 #2
Thanks for the Information, but apparently i posted in the incorrect area. I need information on VBA not VB6

Thanks again.

Wanders off to ask Google.
Jun 15 '10 #3

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

Similar topics

6
by: Kenneth Osenbroch | last post by:
Hi. I want to create a trigger that only allows delete from table A if corresponding record in table B does not exist. Any idea on how this can be done? Thanks, Kenneth.
6
by: Michael | last post by:
I have two tables with a 1-many relationship. I want to write a select statement that looks in the table w/many records and compares it to the records in the primary table to see if there are any...
1
by: Bryan Zash | last post by:
When querying a bit field, I am encountering a problem with MS SQL Server returning a larger number of records for a table than the actual number of records that exist within that table. For...
1
by: Gandalf186 | last post by:
Good morning people, I wish to use VBA to open an Access Query, loop through each record, and then based on the result of a certain field create calculations in which i wish to place as a new...
10
by: Forest14 | last post by:
Hello! Happy Christmas/holidays to you all I have this huge table named "Positions" with more than 160 fields of which the fields are named with non obvious abbreviations. I have another table...
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 =...
1
by: lunas | last post by:
hi i have to update a table based on a criteria with value selected from another table. i am writting a java progg for it . i just want to know can it be done with one statement. my purpose is ...
1
by: dstorms | last post by:
Hi folks, I am trying to set up my database to create a new record in one table when a new record is created in another. Since it is a one-to-one realtionship it certainly would be easier to put...
1
by: Jerh9e1k5 | last post by:
Hi there! I'm trying to organize data into single line exports in order to take it out of a database. The database contains customer information. Some customers have more than one "Business"...
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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?
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
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,...

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.