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 tblMasterEmplyee. If I find a match, I want to take the EmployeeID from that record and put it in tblEEO_EmployeeData, along with the data from the associated record in the old dBase table (tblEEO_DataFromDBase).
2. If no match is found for the SSN in tblMasterEmployee, I want to Insert a new record and place the SSN in the table; save the record and then take the new EmployeeID from tblMasterEmployee with the data in tblEEO_DataFromDBase and place it in tblEEO_EmployeeData
Pretty Simple; huh? :o)
Here is the code: - Dim blnExist As Boolean
-
Dim rstSource As DAO.Recordset
-
Dim rstDest As DAO.Recordset
-
Dim rstGetID As DAO.Recordset
-
Dim lngEmpID As Long
-
Dim lngJGCtr As Long
-
lngJGCtr = 0
-
-
Set rstSource = CurrentDb.OpenRecordset("tblEEO_DataFromDBase")
-
Set rstDest = CurrentDb.OpenRecordset("tblEEO_EmployeeData")
-
Set rstGetID = CurrentDb.OpenRecordset("tblMasterEmployee")
-
-
Do Until rstSource.EOF
-
blnExist = DCount("*", "tblMasterEmployee", "SSN='" & rstSource!SSN & "'")
-
If Not blnExist Then
-
CurrentDb.Execute "insert into tblMasterEmployee (SSN) values ('" & rstGetID!SSN & "')"
-
DoCmd.GoToRecord , , acLast
-
rstGetID.FindFirst "rstGetID [SSN] = '" & rstGetID!SSN & "'"
-
'----------------^Get error on this line "Operation is not supported 'for this object" Run-time error 3251
-
End If
-
-
-
If rstGetID.NoMatch Then
-
MsgBox "Unable to find match!"
-
Else
-
MsgBox "The item is : " & rstGetID![SSN]
-
End If
-
rstDest.AddNew
-
rstDest!EmployeeID = rstGetID!EmployeeID
-
rstDest!Race = rstSource!Race
-
rstDest!Gender = rstSource!Gender
-
rstDest!PositionID = rstSource!Position
-
lngJGCtr = lngJGCtr + 1
-
If lngJGCtr < 6 Then
-
rstDest!JobGroupID = 5
-
Else
-
lngJGCtr = 0
-
rstDest!JobGroupID = 4
-
End If
-
rstDest!CategoryID = rstSource!Category
-
rstDest!Veteran = rstSource!Vet_Stat
-
rstDest!DisVet = rstSource!Dis_Vet
-
rstDest!VietNamVet = rstSource!Nam_Stat
-
rstDest!DisabilityStatus = rstSource!Handicap
-
rstDest!Disability = rstSource!H_Cap
-
rstDest.Update
-
rstSource.MoveNext
-
Loop
-
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.
5 4565
I've made a couple of changes and also I have a question? -
-
Dim blnExist As Boolean
-
Dim rstSource As DAO.Recordset
-
Dim rstDest As DAO.Recordset
-
Dim rstGetID As DAO.Recordset
-
Dim lngEmpID As Long
-
Dim lngJGCtr As Long
-
lngJGCtr = 0
-
-
Set rstSource = CurrentDb.OpenRecordset("tblEEO_DataFromDBase")
-
Set rstDest = CurrentDb.OpenRecordset("tblEEO_EmployeeData")
-
Set rstGetID = CurrentDb.OpenRecordset("tblMasterEmployee")
-
-
rstSource.MoveFirst
-
Do Until rstSource.EOF
-
blnExist = DCount("*", "tblMasterEmployee", "SSN='" & rstSource!SSN & "'")
-
If Not blnExist Then
-
DoCmd.RunSQL "insert into tblMasterEmployee (SSN) values ('" & rstGetID!SSN & "')"
- ' what are you trying to do here?
-
' If you are trying to find the record you've just inserted than you
-
' can't as you would have to close and then reopen the recordset
-
DoCmd.GoToRecord , , acLast
-
rstGetID.FindFirst "rstGetID [SSN] = '" & rstGetID!SSN & "'"
-
-
End If
-
>
-
>
-
>
-
I've made a couple of changes and also I have a question? -
-
Dim blnExist As Boolean
-
Dim rstSource As DAO.Recordset
-
Dim rstDest As DAO.Recordset
-
Dim rstGetID As DAO.Recordset
-
Dim lngEmpID As Long
-
Dim lngJGCtr As Long
-
lngJGCtr = 0
-
-
Set rstSource = CurrentDb.OpenRecordset("tblEEO_DataFromDBase")
-
Set rstDest = CurrentDb.OpenRecordset("tblEEO_EmployeeData")
-
Set rstGetID = CurrentDb.OpenRecordset("tblMasterEmployee")
-
-
rstSource.MoveFirst
-
Do Until rstSource.EOF
-
blnExist = DCount("*", "tblMasterEmployee", "SSN='" & rstSource!SSN & "'")
-
If Not blnExist Then
-
DoCmd.RunSQL "insert into tblMasterEmployee (SSN) values ('" & rstGetID!SSN & "')"
- ' what are you trying to do here?
-
' If you are trying to find the record you've just inserted than you
-
' can't as you would have to close and then reopen the recordset
-
DoCmd.GoToRecord , , acLast
-
rstGetID.FindFirst "rstGetID [SSN] = '" & rstGetID!SSN & "'"
-
-
End If
-
>
-
>
-
>
-
- ' what are you trying to do here?
-
' If you are trying to find the record you've just inserted than you
-
' can't as you would have to close and then reopen the recordset[/b]
-
DoCmd.GoToRecord , , acLast
-
rstGetID.FindFirst "rstGetID [SSN] = '" & rstGetID!SSN & "'"
-
-
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
Try this ... -
-
Dim blnExist As Boolean
-
Dim rstSource As DAO.Recordset
-
Dim rstDest As DAO.Recordset
-
Dim rstGetID As DAO.Recordset
-
Dim lngEmpID As Long
-
Dim lngJGCtr As Long
-
lngJGCtr = 0
-
-
Set rstSource = CurrentDb.OpenRecordset("tblEEO_DataFromDBase")
-
Set rstDest = CurrentDb.OpenRecordset("tblEEO_EmployeeData")
-
Set rstGetID = CurrentDb.OpenRecordset("tblMasterEmployee")
-
-
rstSource.MoveFirst
-
-
Do Until rstSource.EOF
-
blnExist = DCount("*", "tblMasterEmployee", "SSN='" & rstSource!SSN & "'")
-
If Not blnExist Then
-
rstGetID.FindFirst "[SSN] = '" & rstSource!SSN & "'"
-
DoCmd.RunSQL "insert into tblMasterEmployee (SSN) values ('" & rstGetID!SSN & "')"
-
End If
-
If rstGetID.NoMatch Then
-
MsgBox "Unable to find match!"
-
Else
-
MsgBox "The item is : " & rstGetID![SSN]
-
End If
-
rstDest.AddNew
-
rstDest!EmployeeID = rstGetID!EmployeeID
-
rstDest!Race = rstSource!Race
-
rstDest!Gender = rstSource!Gender
-
rstDest!PositionID = rstSource!Position
-
lngJGCtr = lngJGCtr + 1
-
If lngJGCtr < 6 Then
-
rstDest!JobGroupID = 5
-
Else
-
lngJGCtr = 0
-
rstDest!JobGroupID = 4
-
End If
-
rstDest!CategoryID = rstSource!Category
-
rstDest!Veteran = rstSource!Vet_Stat
-
rstDest!DisVet = rstSource!Dis_Vet
-
rstDest!VietNamVet = rstSource!Nam_Stat
-
rstDest!DisabilityStatus = rstSource!Handicap
-
rstDest!Disability = rstSource!H_Cap
-
rstDest.Update
-
rstSource.MoveNext
-
Loop
-
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: - Do Until rstSource.EOF
-
blnExist = DCount("*", "tblMasterEmployee", "SSN='" & rstSource!SSN & "'")
-
' If Not blnExist Then
-
' rstGetID.FindFirst "[SSN] = '" & rstSource!SSN & "'"
-
' DoCmd.RunSQL "insert into tblMasterEmployee (SSN) values ('" & rstGetID!SSN & "')"
-
' End If
-
rstGetID.FindFirst "[SSN] = '" & rstSource!SSN & "'"
-
If rstGetID.NoMatch Then
-
'..............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.
I figured it out. I needed to add dbOpenDynaset to Current.db statements: - Set rstSource = CurrentDb.OpenRecordset("tblEEO_DataFromDBase", dbOpenDynaset)
-
Set rstDest = CurrentDb.OpenRecordset("tblEEO_EmployeeData", dbOpenDynaset)
-
Set rstGetID = CurrentDb.OpenRecordset("tblMasterEmployee", dbOpenDynaset)
Thanks for pointing me in the right direction. Have a blessed day as you have blessed mine.
David
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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!...
|
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...
|
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),...
|
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...
|
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...
|
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...
|
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...
|
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,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
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
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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...
|
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: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |