Transfer data from SQL server to Access 
Author Message
 Transfer data from SQL server to Access

Dear NG,

I am using Access 97 SR-2 and ADO 2.0 and I want to create a new table in
Access and insert in this new table data from a SQL Server.
With the help of ADO I get the data from the SQL server, but how can I
insert this data into an Access table.
Please see the example of my code below! The code is running in Access,
because Access will be the front-end.

Thank you very much in advance for any help!

With best regards,
Sabine

Example:
Sub MainTestAccessToSQL()
    Dim adocon As Object
    Dim adocmd As Object
    Dim adoparam As Object
    Dim ado_set As Object
    Dim Gb As String
    Dim PPT As String
    Dim Kat As String
    Dim LfdNr   As String
    Dim Ver As String
    Dim Rev As String
    Dim bLogin As Boolean
    Dim DokID As String

    bLogin = False

    If iLogInSQLServer(adocon, adocmd, adoparam) = False Then
        MsgBox "Could not login"
        GoTo Ende
    Else
        bLogin = True
    End If

    Gb = "3"
    PPT = "OPSC_TEI"
    Kat = "SDE"
    LfdNr = "1"
    Ver = "1"
    Rev = "0"

    Set ado_set = CreateObject("ADODB.Recordset")

    ado_set.Open "SELECT * FROM OPDS", adocon
    If Not ado_set.EOF Then
        MsgBox ado_set!titel
    End If

    '### How to insert the data of ado_set into an Access table?

Ende:
    If bLogin = True Then
        Call iLogOutSQLServer(adocon, adocmd, adoparam)
    End If

End Sub



Fri, 31 Dec 2004 14:15:46 GMT  
 Transfer data from SQL server to Access
Hi,

You could use different approaches to do that. First is to use DTS COM
model, which comes with SQL Server. Second is to use OLEDB provider for Jet.
Here is an small example with Jet

    Dim loConnection As ADODB.Connection
    Dim lcSQL As String

    Set loConnection = New ADODB.Connection
    loConnection.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
               "Data Source=place path to mdb file here;"

    lcSQL = "SELECT * INTO Products_Backup FROM [odbc;Driver={SQL
Server};Server=(local);"
    lcSQL = lcSQL & "Database=northwind;Uid=sa;Pwd=;].Products"

    loConnection.Execute lcSQL, , adExecuteNoRecords
    loConnection.Close

--
Val Mazur
Microsoft MVP

Quote:

> Dear NG,

> I am using Access 97 SR-2 and ADO 2.0 and I want to create a new table in
> Access and insert in this new table data from a SQL Server.
> With the help of ADO I get the data from the SQL server, but how can I
> insert this data into an Access table.
> Please see the example of my code below! The code is running in Access,
> because Access will be the front-end.

> Thank you very much in advance for any help!

> With best regards,
> Sabine

> Example:
> Sub MainTestAccessToSQL()
>     Dim adocon As Object
>     Dim adocmd As Object
>     Dim adoparam As Object
>     Dim ado_set As Object
>     Dim Gb As String
>     Dim PPT As String
>     Dim Kat As String
>     Dim LfdNr   As String
>     Dim Ver As String
>     Dim Rev As String
>     Dim bLogin As Boolean
>     Dim DokID As String

>     bLogin = False

>     If iLogInSQLServer(adocon, adocmd, adoparam) = False Then
>         MsgBox "Could not login"
>         GoTo Ende
>     Else
>         bLogin = True
>     End If

>     Gb = "3"
>     PPT = "OPSC_TEI"
>     Kat = "SDE"
>     LfdNr = "1"
>     Ver = "1"
>     Rev = "0"

>     Set ado_set = CreateObject("ADODB.Recordset")

>     ado_set.Open "SELECT * FROM OPDS", adocon
>     If Not ado_set.EOF Then
>         MsgBox ado_set!titel
>     End If

>     '### How to insert the data of ado_set into an Access table?

> Ende:
>     If bLogin = True Then
>         Call iLogOutSQLServer(adocon, adocmd, adoparam)
>     End If

> End Sub



Fri, 31 Dec 2004 19:38:11 GMT  
 Transfer data from SQL server to Access
Hello,

first of all thank you for your answer, but I do not think this is the
solution that I am looking for.
Am I right that your example should run on the SQL Server?
I need the solution to insert the data from the SQL Server into a new or
existing Access table using an Access program.
In the Access program I had already the solution to get the data from the
SQL Server into a recordset.
But how can I insert this recordset into a new or existing Access table?
Furthermore I do not want to use ODBC, because the Access front-end is
stored in a network and will run on different PCs.

With best regards,
Sabine

Quote:
> Hi,

> You could use different approaches to do that. First is to use DTS COM
> model, which comes with SQL Server. Second is to use OLEDB provider for
Jet.
> Here is an small example with Jet

>     Dim loConnection As ADODB.Connection
>     Dim lcSQL As String

>     Set loConnection = New ADODB.Connection
>     loConnection.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
>                "Data Source=place path to mdb file here;"

>     lcSQL = "SELECT * INTO Products_Backup FROM [odbc;Driver={SQL
> Server};Server=(local);"
>     lcSQL = lcSQL & "Database=northwind;Uid=sa;Pwd=;].Products"

>     loConnection.Execute lcSQL, , adExecuteNoRecords
>     loConnection.Close

> --
> Val Mazur
> Microsoft MVP



Sat, 01 Jan 2005 14:35:19 GMT  
 Transfer data from SQL server to Access
Hi,

My example written on VB and you could run it from Access. It is not related
to SQL Server and uses JET provider to transfer data. If you do not want to
use ODBC, then I think you should have a look onto SQL DTS. It allows to
transfer data between different datasources.
If you already have recordset, then you could insert information from it
looping through records and insert them one-by-one.

--
Val Mazur
Microsoft MVP

Quote:

> Hello,

> first of all thank you for your answer, but I do not think this is the
> solution that I am looking for.
> Am I right that your example should run on the SQL Server?
> I need the solution to insert the data from the SQL Server into a new or
> existing Access table using an Access program.
> In the Access program I had already the solution to get the data from the
> SQL Server into a recordset.
> But how can I insert this recordset into a new or existing Access table?
> Furthermore I do not want to use ODBC, because the Access front-end is
> stored in a network and will run on different PCs.

> With best regards,
> Sabine

> > Hi,

> > You could use different approaches to do that. First is to use DTS COM
> > model, which comes with SQL Server. Second is to use OLEDB provider for
> Jet.
> > Here is an small example with Jet

> >     Dim loConnection As ADODB.Connection
> >     Dim lcSQL As String

> >     Set loConnection = New ADODB.Connection
> >     loConnection.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
> >                "Data Source=place path to mdb file here;"

> >     lcSQL = "SELECT * INTO Products_Backup FROM [odbc;Driver={SQL
> > Server};Server=(local);"
> >     lcSQL = lcSQL & "Database=northwind;Uid=sa;Pwd=;].Products"

> >     loConnection.Execute lcSQL, , adExecuteNoRecords
> >     loConnection.Close

> > --
> > Val Mazur
> > Microsoft MVP



Sat, 01 Jan 2005 19:36:09 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. transferring access database to sql server

2. transferring access database to sql server please help

3. Can I use an SQL action query to transfer data between DIFFERENT Access .mdb files

4. Transfer SQL Server table between servers in VB code

5. Transfer SQL Server table between servers in VB code

6. sql server connect. Migration Access->sql server

7. sql server connect. Migration Access->sql server

8. sql server connect. Migration Access->sql server

9. MS Access 2002 vs VB.net as a front-end to SQL Server data

10. Outlook custom CONTACT form accessing SQL Server data

11. convert data between access to sql server

12. Insert Data Into Access Database From SQL Server ADO Insert

 

 
Powered by phpBB® Forum Software