473,785 Members | 2,312 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

"Insert Into" statement not working

21 New Member
Good Day All, I have some EEO data in an old dBase4 database that I have converted to an Access table. Since dBase was not a relational database, I didn't create any key fields. I linked all of the tables together on Employees' SSN; therefore, in order to use this data with the current Access database, I need to create a relationship between the old dBase4 EEO data and the Access employee data. The Access employee data was also an old dBase table, but after importing it into Access and adding a key field, EmployeeID, Access automatically assigned a number to each of my 1,200+ records. This part of the equation was simple, and additionally, I am attempting to do a few other things here:

1st - I need to use the SSN in the old dBase data (EEO) and do a FindFirst in tblMasterEmplye e. If I find a match, I want to take the EmployeeID from that record and put it in tblEEO_Employee Data, along with the data from the associated record in the old dBase table (tblEEO_DataFro mDBase).

2. If no match is found for the SSN in tblMasterEmploy ee, I want to Insert a new record and place the SSN in the table; save the record and then take the new EmployeeID from tblMasterEmploy ee with the data in tblEEO_DataFrom DBase and place it in tblEEO_Employee Data

Pretty Simple; huh? :o)

Here is the code:

Expand|Select|Wrap|Line Numbers
  1.     Dim blnExist As Boolean
  2.     Dim rstSource As DAO.Recordset
  3.     Dim rstDest As DAO.Recordset
  4.     Dim rstGetID As DAO.Recordset
  5.     Dim lngEmpID As Long
  6.     Dim lngJGCtr As Long
  7.     lngJGCtr = 0
  8.  
  9.     Set rstSource = CurrentDb.OpenRecordset("tblEEO_DataFromDBase")
  10.     Set rstDest = CurrentDb.OpenRecordset("tblEEO_EmployeeData")
  11.     Set rstGetID = CurrentDb.OpenRecordset("tblMasterEmployee")
  12.  
  13.     Do Until rstSource.EOF
  14.         blnExist = DCount("*", "tblMasterEmployee", "SSN='" & rstSource!SSN & "'")
  15.         If Not blnExist Then
  16.             CurrentDb.Execute "insert into tblMasterEmployee (SSN) values ('" & rstGetID!SSN & "')"
  17.             DoCmd.GoToRecord , , acLast
  18.             rstGetID.FindFirst "rstGetID [SSN] = '" & rstGetID!SSN & "'"
  19. '----------------^Get error on this line "Operation is not supported 'for this object" Run-time error 3251 
  20.         End If
  21.  
  22.  
  23.             If rstGetID.NoMatch Then
  24.                 MsgBox "Unable to find match!"
  25.             Else
  26.                 MsgBox "The item is : " & rstGetID![SSN]
  27.             End If  
  28.             rstDest.AddNew
  29.             rstDest!EmployeeID = rstGetID!EmployeeID
  30.             rstDest!Race = rstSource!Race
  31.             rstDest!Gender = rstSource!Gender
  32.             rstDest!PositionID = rstSource!Position
  33.             lngJGCtr = lngJGCtr + 1
  34.             If lngJGCtr < 6 Then
  35.                rstDest!JobGroupID = 5
  36.             Else
  37.                lngJGCtr = 0
  38.                rstDest!JobGroupID = 4
  39.             End If
  40.             rstDest!CategoryID = rstSource!Category
  41.             rstDest!Veteran = rstSource!Vet_Stat
  42.             rstDest!DisVet = rstSource!Dis_Vet
  43.             rstDest!VietNamVet = rstSource!Nam_Stat
  44.             rstDest!DisabilityStatus = rstSource!Handicap
  45.             rstDest!Disability = rstSource!H_Cap
  46.             rstDest.Update
  47.             rstSource.MoveNext
  48.     Loop
  49.  
The program keeps blowing up at the Insert Into command with the following error:

"Operation is not supported for this object" Run-time error 3251

That error is only if SSN not found and I attempt to add the record and then find it for applicable data manipulation. However, all of the records that exist and do process shows an EmployeeID of the number "1". The first person in rstGetID has an employeeID of 1, so for reason, the program is only reading the first record.

Many thanks to whoever comes to my rescue.

David

Running on Windows XP and Access 2002 in 2000 mode.
Mar 29 '07 #1
5 4592
MMcCarthy
14,534 Recognized Expert Moderator MVP
I've made a couple of changes and also I have a question?

Expand|Select|Wrap|Line Numbers
  1.  
  2. Dim blnExist As Boolean
  3.     Dim rstSource As DAO.Recordset
  4.     Dim rstDest As DAO.Recordset
  5.     Dim rstGetID As DAO.Recordset
  6.     Dim lngEmpID As Long
  7.     Dim lngJGCtr As Long
  8.     lngJGCtr = 0
  9.  
  10.     Set rstSource = CurrentDb.OpenRecordset("tblEEO_DataFromDBase")
  11.     Set rstDest = CurrentDb.OpenRecordset("tblEEO_EmployeeData")
  12.     Set rstGetID = CurrentDb.OpenRecordset("tblMasterEmployee")
  13.  
  14.     rstSource.MoveFirst
  15.     Do Until rstSource.EOF
  16.         blnExist = DCount("*", "tblMasterEmployee", "SSN='" & rstSource!SSN & "'")
  17.         If Not blnExist Then
  18.        DoCmd.RunSQL "insert into tblMasterEmployee (SSN) values ('" & rstGetID!SSN & "')"
  19. ' what are you trying to do here? 
  20. ' If you are trying to find the record you've just inserted than you
  21. ' can't as you would have to close and then reopen the recordset
  22.             DoCmd.GoToRecord , , acLast 
  23.             rstGetID.FindFirst "rstGetID [SSN] = '" & rstGetID!SSN & "'"
  24.  
  25.         End If
  26. >
  27. >
  28. >
  29.  
Mar 30 '07 #2
djsdaddy
21 New Member
I've made a couple of changes and also I have a question?

Expand|Select|Wrap|Line Numbers
  1.  
  2. Dim blnExist As Boolean
  3.     Dim rstSource As DAO.Recordset
  4.     Dim rstDest As DAO.Recordset
  5.     Dim rstGetID As DAO.Recordset
  6.     Dim lngEmpID As Long
  7.     Dim lngJGCtr As Long
  8.     lngJGCtr = 0
  9.  
  10.     Set rstSource = CurrentDb.OpenRecordset("tblEEO_DataFromDBase")
  11.     Set rstDest = CurrentDb.OpenRecordset("tblEEO_EmployeeData")
  12.     Set rstGetID = CurrentDb.OpenRecordset("tblMasterEmployee")
  13.  
  14.     rstSource.MoveFirst
  15.     Do Until rstSource.EOF
  16.         blnExist = DCount("*", "tblMasterEmployee", "SSN='" & rstSource!SSN & "'")
  17.         If Not blnExist Then
  18.        DoCmd.RunSQL "insert into tblMasterEmployee (SSN) values ('" & rstGetID!SSN & "')"
  19. ' what are you trying to do here? 
  20. ' If you are trying to find the record you've just inserted than you
  21. ' can't as you would have to close and then reopen the recordset
  22.             DoCmd.GoToRecord , , acLast 
  23.             rstGetID.FindFirst "rstGetID [SSN] = '" & rstGetID!SSN & "'"
  24.  
  25.         End If
  26. >
  27. >
  28. >
  29.  
Expand|Select|Wrap|Line Numbers
  1. ' what are you trying to do here? 
  2. ' If you are trying to find the record you've just inserted than you
  3. ' can't as you would have to close and then reopen the recordset[/b]
  4.             DoCmd.GoToRecord , , acLast 
  5.             rstGetID.FindFirst "rstGetID [SSN] = '" & rstGetID!SSN & "'"
  6.  
  7.         End If
Thanks for the insight and assistance. I mistakenly thought that you had to save the record before you could manipulate the data. After looking at your code, I only included the DoCmd.RunSQL command, and although it ran through the EOF of the recordset, all 1,200+ records still has an EmployeeID of 1. So for some reason my logic is forcing the program to only read the first record of the rstGetID recordset.

Any more suggestions?

David
Mar 30 '07 #3
MMcCarthy
14,534 Recognized Expert Moderator MVP
Try this ...

Expand|Select|Wrap|Line Numbers
  1.  
  2. Dim blnExist As Boolean
  3.     Dim rstSource As DAO.Recordset
  4.     Dim rstDest As DAO.Recordset
  5.     Dim rstGetID As DAO.Recordset
  6.     Dim lngEmpID As Long
  7.     Dim lngJGCtr As Long
  8.     lngJGCtr = 0
  9.  
  10.     Set rstSource = CurrentDb.OpenRecordset("tblEEO_DataFromDBase")
  11.     Set rstDest = CurrentDb.OpenRecordset("tblEEO_EmployeeData")
  12.     Set rstGetID = CurrentDb.OpenRecordset("tblMasterEmployee")
  13.  
  14.     rstSource.MoveFirst
  15.  
  16.     Do Until rstSource.EOF
  17.         blnExist = DCount("*", "tblMasterEmployee", "SSN='" & rstSource!SSN & "'")
  18.         If Not blnExist Then
  19.       rstGetID.FindFirst "[SSN] = '" & rstSource!SSN & "'"
  20.        DoCmd.RunSQL "insert into tblMasterEmployee (SSN) values ('" & rstGetID!SSN & "')"
  21.         End If
  22.       If rstGetID.NoMatch Then
  23.                 MsgBox "Unable to find match!"
  24.             Else
  25.                 MsgBox "The item is : " & rstGetID![SSN]
  26.             End If  
  27.             rstDest.AddNew
  28.             rstDest!EmployeeID = rstGetID!EmployeeID
  29.             rstDest!Race = rstSource!Race
  30.             rstDest!Gender = rstSource!Gender
  31.             rstDest!PositionID = rstSource!Position
  32.             lngJGCtr = lngJGCtr + 1
  33.             If lngJGCtr < 6 Then
  34.                rstDest!JobGroupID = 5
  35.             Else
  36.                lngJGCtr = 0
  37.                rstDest!JobGroupID = 4
  38.             End If
  39.             rstDest!CategoryID = rstSource!Category
  40.             rstDest!Veteran = rstSource!Vet_Stat
  41.             rstDest!DisVet = rstSource!Dis_Vet
  42.             rstDest!VietNamVet = rstSource!Nam_Stat
  43.             rstDest!DisabilityStatus = rstSource!Handicap
  44.             rstDest!Disability = rstSource!H_Cap
  45.             rstDest.Update
  46.             rstSource.MoveNext
  47.     Loop
  48.  
Mar 30 '07 #4
djsdaddy
21 New Member
The "If Not blnExist " condition was never true, so the program never hit the FindFirst statment. I commented out the If-Then statement, but still used the fiindfirst:

Expand|Select|Wrap|Line Numbers
  1. Do Until rstSource.EOF
  2.         blnExist = DCount("*", "tblMasterEmployee", "SSN='" & rstSource!SSN & "'")
  3. '        If Not blnExist Then
  4. '            rstGetID.FindFirst "[SSN] = '" & rstSource!SSN & "'"
  5. '            DoCmd.RunSQL "insert into tblMasterEmployee (SSN) values ('" & rstGetID!SSN & "')"
  6. '        End If
  7.         rstGetID.FindFirst "[SSN] = '" & rstSource!SSN & "'"
  8.         If rstGetID.NoMatch Then
  9. '..............Rest of code
I received the following error:

Run-time error 3251 Operation is not supported for this type of object

However, when I ran your code with the If-Then statement, I noticed that the program is never finding a match on SSN in rstGetID, so the recordset pointer is always sitting at the first record, which is why when the program runs through EOF, all of the EmployeeIDs in rstDest is 1. For some reason, Access appears not to like the the FindFirst statement with the rstGetID recordset.
Mar 30 '07 #5
djsdaddy
21 New Member
I figured it out. I needed to add dbOpenDynaset to Current.db statements:

Expand|Select|Wrap|Line Numbers
  1. Set rstSource = CurrentDb.OpenRecordset("tblEEO_DataFromDBase", dbOpenDynaset)
  2. Set rstDest = CurrentDb.OpenRecordset("tblEEO_EmployeeData", dbOpenDynaset)
  3. Set rstGetID = CurrentDb.OpenRecordset("tblMasterEmployee", dbOpenDynaset)
Thanks for pointing me in the right direction. Have a blessed day as you have blessed mine.

David
Mar 30 '07 #6

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

Similar topics

2
5649
by: newbie_mw | last post by:
Hi, I need urgent help with a novice problem. I would appreciate any advice, suggestions... Thanks a lot in advance! Here it is: I created a sign-up sheet (reg.html) where people fill in their first name, last name, email, etc. The data are then sent to a PHP script (reg.php). The data are then inserted into a table (reg) in MS SQL server. I have declared the variables like this: if (!(isset($_POST))) { $FirstName = "" ;
1
4539
by: newbie_mw | last post by:
Seems my post was buried in more cries for help :-) I will try again. It's probably a very novice question so please take a look! Thanks! ----------------------------------------------------------------- I created a sign-up sheet (reg.html) where people fill in their first name, last name, email, etc. The data are then sent to a PHP script (reg.php). The data are then inserted into a table (reg) in MS SQL server. I have declared the...
5
3099
by: Chad Richardson | last post by:
Is there a way in SQL Server 2000 to extract data from a table, such that the result is a text file in the format of "Insert Into..." statements, i.e. if the table has 5 rows, the result would be 5 lines of : insert into Table (, , .... VALUES a,b,c) insert into Table (, , .... VALUES d, e, f) insert into Table (, , .... VALUES g, h, i) insert into Table (, , .... VALUES j, k, l) insert into Table (, , .... VALUES m, n, o)
3
4593
by: anurag | last post by:
Hi, Is "MERGE INTO..." statement allowed to be executed in a dynamic SQL statement, inside an SQL Stored Procedure? I am using DB2 UDB 8.1.2 on Windows. If it is not allowed (as I suspect), how do I go about converting an Oracle Procedure that dynamically executes "MERGE INTO..."? ONE RESTRICTION: My converted code has to execute faster than the Oracle SP (everything else being the same).
20
18388
by: Mark Harrison | last post by:
So I have some data that I want to put into a table. If the row already exists (as defined by the primary key), I would like to update the row. Otherwise, I would like to insert the row. I've been doing something like delete from foo where name = 'xx'; insert into foo values('xx',1,2,...);
4
2544
by: Takeadoe | last post by:
Dear NG - I've got a bunch of SQL statements (Insert Into "Access Table Name") generated from another software program. They look like this: Pasting these lines into the SQL view as they are generates a couple of different errors (missing semicolon being one of them). They work fine if I paste 1 line at a time. Can someone tell me what I need to do to remedy the situation? I can't hardly paste 1 at a time! Your help is very much...
4
13203
by: Bart op de grote markt | last post by:
Hello I used to work in a Sybase database environment. When I had to insert/ update records in the database, I always used "insert on existing update", in this way, you didn't have to check whether a record already existed (avoid errors) and you were always sure that after running the scripts, the last version was in the database. Now I'm looking for the same functionality in MS SQL Server, asked a few people, but nobody knows about...
6
6005
by: ewpatton | last post by:
Good day, I've been trying to work with SQL and an Access database in order to handle custom user profiles. I haven't had any trouble reading from my database, but inserting new entries into it has been troublesome to say the least. My ASP.NET script is supposed to execute an INSERT INTO statement in order to add a user to the database. Here is a sample:
2
3404
by: paulquinlan100 | last post by:
Hi I'm using automation in excel to insert a lot of data into an Access DB. Its all working fine, apart from the fact that the data entry people occasionally put "n/a" in the cells instead of 0, which obviously access doesnt like being put into a number field. I know i can put if statements around every variable to check, but is there a way to force it to just put the default value for that particular field (mostly 0, but sometimes it...
0
9643
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
10315
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...
0
9946
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...
0
8968
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7494
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
6737
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5379
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
4044
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
3645
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.