473,659 Members | 2,664 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

23 New Member
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 1407
vb5prgrmr
305 Recognized Expert Contributor
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
lee weaver
23 New Member
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
7643
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
130050
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 records that do not match based on a certain field. Here is how my tables are setup: Task Code Table TCode,TCodeFName,Active
1
2635
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 example, my customer table has 1 million unique records, so the results of the following query are as such: select count(customer_nbr) from customer = 1,000,000 There is bit field in the customer table that denotes whether a
1
34157
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 record in a new table. If anyone out there can give be the basic code that will : - Collect the Data, Loop through data create a new table post variable to the new table (as records).
10
4312
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 named "definitions" which has the column name and definition fields. In order to help me all along my forthcoming developments, I would like to use these definitions from table "definitions" into "Positions". Of course i can manually copy each...
7
7213
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 = "xxxx"; $pwd = "xxxxx"; $db = "xxxxx";
1
1692
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 result set rs =select (ID) from Tab1 where colmB is null LOOP rs select ID2 from tab2 where colC=ID
1
2201
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 the data into one table. Originally it was one table, but I split the table to create conditional field-level security (read-only unless one box was unchecked). However I'm trying to fix one flaw in the whole scheme: When a user adds a new record in...
1
1163
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" phone number. I've managed to divide up the phone numbers into "Business" and "Business2" through a query which I then transformed into a table. Now I want to use this new table to update the master table. Keep in mind that not all instances of...
1
1975
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 retrieved field value into another table from the same form.i m using session but not working. how can i do this?can anyone please solve it for me. Thanks.
0
8427
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8330
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8850
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8523
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8626
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6178
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4175
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2749
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1737
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.