Solved

Updating Microsoft access data to SQL server data

Posted on 2000-03-08
5
178 Views
Last Modified: 2010-08-05
I had a Microsoft Access 97 data table call template sited at local drive with the following fields:
ProductNo, DealerPrice, updateRecord

I had SQL Data table call searchIndex sited at SQL server with the following fields:
ProductNo, TableName, updateRecord

My program is to read access recordset ProductNo and than read SQL recordset ProductNo.

When SQL recordset ProductNo equal to Access recordset ProductNo, the SQL updateRecord will set to 1.

This means that the product need to update its DearPrice and ListPrice from the access table. But this update is not to be done on the searchIndex SQL table.

The things is the program need to read SQL searchIndex field TableName. TableName refer to company name and contain ProductNo, DealerPrice and ListPrice. There are about 1000 records of company name in SQL server.

Here the part that I don't know how to approach using visual basic.


I create two ADO object, one is to read SQL data and one for Access data, and a command click object to update the data.

this section it work that the program update the updateRecord field to 1.

Hope this is not confuse.

The whole process is:

Read Access data, read SQL data, compare the ProductNo, update the updateRecord field. If updateRecord field is 1, read TableName.

for example, the TableName APC is a set of table data with fields such as ProductNo, DealerPrice, ListPrice.

How then can I using ADO in visual baisc to go to the company name after reading the TableName recordset at SQL searchIndex table.

As ADO only access to 1 database record file...if am right, then I had problem access to the company table.

Is there a way to solve this problem?

Many Thanks in advance.


0
Comment
Question by:felicia
5 Comments
 
LVL 4

Expert Comment

by:wqw
Comment Utility
absolutely impossible.... :-)) just kidding

well, ado is reading as much record files (???columns???) as you want this way:

Dim rs as New Recordset
rs.Open "Select * from searchIndex", <YourConnectStringToSQL>

</wqw>

p.s. i give up. this is too basic. find a book on SQL
0
 
LVL 12

Expert Comment

by:roverm
Comment Utility
If I understand correct:

The Access table is your backbone for your application: If the user does anything, the updateRecord field is set to 1 to indicate that the 'master' database needs to be updated.

Then you look in the indexSearch SQL for the comparing ProductNo, and if found collect the TableName.

Then in the table TABLENAME (????) you have to look for that productno and update it.

It this correct ? So you have different table names which contain ProductNo's ?
Are u using SQL Server (7) ?

Let me know!

D'Mzzl!
RoverM
0
 
LVL 43

Accepted Solution

by:
TimCottee earned 200 total points
Comment Utility
Here is a potential example, I have just knocked it out so there may be errors which you will have to sort out. It requires a reference to ADO in your project. The process is:

Read access table, go through records one by one, find equivalent record in searchindex, set updaterecord = 1, read table name, open this table at the same product no and update the values from the current access record. I have assumed that the productno field is character rather than numeric, if it is numeric then remove the single quote bits :- '.

Dim cnnAccess As ADODB.Connection
Dim cnnSQL As ADODB.Connection
Dim rstAccess As ADODB.Recordset
Dim rstSQL As ADODB.Recordset
Set cnnAccess = New ADODB.Connection
Set cnnSQL = New ADODB.Connection
cnnAccess.ConnectionString = "Insert Connection String For Access DB"
cnnSQL.ConnectionString = "Insert Connection String For SQL DB"
cnnAccess.Open
cnnSQL.Open
Set rstAccess = New ADODB.Recordset
rstAccess.Open "SELECT * FROM <AccessTableName>",cnnAccess,adOpenStatic,adLockOptimistic
With rstAccess
  .MoveFirst
  Do
    rstSQL.Open "SELECT * FROM SearchIndex WHERE ProductNo = '" & rstAccess!ProductNo & "'",cnnSQL,adOpenStatic,adLockOptimistic
    rstSQL!UpdateRecord = 1
    rstSQL.Update
    strTableName = rstSQL!TableName
    rstSQL.Close
    rstSQL.Open "SELECT * FROM " & strTableName & " WHERE ProductNo = '" & rstAccess!ProductNo & "'",cnnSQL,adOpenStatic,adLockOptimistic
    rstSQL!DealerPrice = rstAccess!DealerPrice
    'and so on
    rstSQL.Close
    .MoveNext
  Loop Until .Eof
End With
IF rstSQL.State = adStateOpen Then rstSQL.Close
IF rstAccess.State = adStateOpen Then rstAccess.Close
cnnAccess.Close
cnnSQL.Close
Set rstSQL = Nothing
Set rstAccess = Nothing
Set cnnSQL = Nothing
Set cnnAccess = Nothing
0
 

Author Comment

by:felicia
Comment Utility
Many Thanks TimCottee's.

However, my code was different from my approach.

Can u give comments about my approach.

Attached for your reference.

Private Sub cmdUpdatPrice_Click()
    adosql.Refresh
    adoaccess.Refresh
    'adoaccess.Recordset.RecordCount
    Label1.Caption = adoaccess.Recordset.RecordCount
     
   
    Do While Not adoaccess.Recordset.EOF
        adosql.Recordset.MoveFirst
        adosql.Recordset.Find "ProductNo='" & adoaccess.Recordset.Fields("ProductNo") & "'"
       
        If Not adosql.Recordset.EOF Then
             
            adosql.Recordset.Fields("updateRecord") = True
            adoaccess.Recordset.Fields("updateRecord") = True
            adosql.Recordset.Update
            adoaccess.Recordset.Update
                               
           
        End If
        adoaccess.Recordset.MoveNext
        Loop
     
End Sub


Thanks you very much.

0
 
LVL 43

Expert Comment

by:TimCottee
Comment Utility
Your approach is not really that different, the major difference is that you have opened the entire SQL table and used Find to get the appropriate record whereas I have opened the sql table on each row with only the matching row in the recordset, I can't really say which is better, if the SQL table is small then using VB to do the find may not be a problem, however if the SQL table is large, using find which is at the client level may be slower than opening the recordset each time with one record as it is then up to the SQL server to do the work not the vb client.

But neither is wrong.

0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

744 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

16 Experts available now in Live!

Get 1:1 Help Now