Solved

verify if record exist before updating (migration vb program)

Posted on 2009-04-01
3
383 Views
Last Modified: 2013-12-25
Hi Guys

I have vb program to migrate records from old db to a new model.
This is the situation
tbl-Old
ID  CustID     Location
1          1        Newark
2          1        Denver
3          1        NY
4          1        NY
5          1        Newark


New-Model
ID   CustID   Location
1        1          Newark
2        1          Denver
3        1          NY

This is how it should be transfer, so before i update the new record, i have to verify if the CustID and Location already exist
I have the code that will transfer everything without comparing or verifying is it exist

Any comments  
0
Comment
Question by:titorober23
  • 2
3 Comments
 
LVL 17

Expert Comment

by:k_murli_krishna
ID: 24042457
Fire SEELCT CustID,  Location FROM tbl-Old and New-Model separately WHERE ID = 1, 2, 3 etc. compare them in code using Cursor/ResultSet/Iterator and if same then do not migrate else go ahead. For this if databases are different does not matter in single Access, different access in different systems as long as you maintain separate connection objects/contexts from application to them.

The other way is to let the code be as is developed and just introduce error/exception handling code where by if constraint violation prevents the migration, then dummy handle the vilation error/exception. It is not just a question of CustID and Location already existing but here more a question of PK ID in source and target both being present before data migration takes place.

If only one connection is possible at a time like in stored procedures, then link the databases/their tables like we have db link in Oracle, nicknames in DB2 and four part name in SQL Server and Sybase i.e. server.db.schema/owner.object.
0
 

Accepted Solution

by:
titorober23 earned 0 total points
ID: 24051600
I did a function that will check if the record already exist , if so it won't add a new record, thsi si the code for the function

Function AlreadyIn(ByVal POldID As Long, ByVal NLoc As String) As Boolean
    Dim rsNLOT As DAo.Recordset

    Set rsNLOT = CurrentDb.OpenRecordset("SELECT * FROM [LocationDetails] WHERE (([Type]='Branch') AND ([CustID] = " & POldID & ") AND ([Location]='" & NLoc & "'))")
   
    'Iterate through records from old table
    If rsNLOT.EOF Then
        AlreadyIn = False
        Exit Function
    Else
        rsNLOT.MoveLast
        AlreadyIn = True
        Exit Function
    End If
    rsNLOT.Close
End Function
0
 
LVL 17

Expert Comment

by:k_murli_krishna
ID: 24052078
Good. Fire a select query from both old and new tables while passing columns as parameters to your function so that if boolean returned is TRUE, then do not carry out the migration of these records else do so for the rest.
0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now