Solved

Pulling Great Plains odbc connected tables into Access

Posted on 2009-04-03
12
1,024 Views
Last Modified: 2013-11-27
I am trying to automate the download of tables out of Great  Plains into Access.  I have an entire process of queries setup in a macro; however, to initiate the login to sql, I was told I must use code as follows:

'LOGON CODE:
   Dim cnn As ADODB.Connection
   Dim rs As ADODB.Recordset
   Set cnn = New ADODB.Connection
   cnn.ConnectionString = "driver={SQL Server};" & "server=MySqlServer;uid=sa;Pwd=password;database=pubs"

'EXECUTION CODE:
  cnn.Open
  cnn.Execute ("INSERT INTO localtable SELECT IVC30101.* FROM IVC30101;")
    DoEvents

The problem is that the code is is trying to, I believe, write the table in the sql database - not the local Access mdb.  Even though the connection is established, I can then not run a macro to do the query and subsequent steps because it brings up the sql login box.

So, the way I see it, the problem can be solved 2 ways -
1) Allow the login from the first part of the code above to be used in the Access database queries to pull from the Great Plains tables without reentering the password.
2) Modify the sql above so that the INSERT area will actually insert into a local table.

Any suggestions would be GREATLY appreciated.
0
Comment
Question by:sd854282
  • 6
  • 5
12 Comments
 
LVL 11

Expert Comment

by:mildurait
ID: 24067040

<cnn.Execute ("INSERT INTO localtable SELECT IVC30101.* FROM IVC30101;")>
Aside from the sql connection issue, the code would insert data into a table called localtable within the gp sql database.
Suggest linking table IVC30101 Using File / Get External Data / Link tables and renaming the linked table to IVC30101.

Then you can run the code
Call docmd.runsql("INSERT INTO INSERT INTO localtable SELECT IVC30101.* FROM IVC30101;")



0
 

Author Comment

by:sd854282
ID: 24072738
Thanks.  The above does get it into the local Access mdb instead of sql.  However, the login issue is still present.

0
 
LVL 11

Expert Comment

by:mildurait
ID: 24073127
The data is still in sql, it just a appears as a linked table.
There should be an option that you can check to remember username and password when you link the table.
0
 

Author Comment

by:sd854282
ID: 24103450
My mistake....the  code above did NOT get it into a local table in the Access database. My error message states, "[Microsoft][ODBC SQL Server Driver][SQL Server]Invalid object name localtable.

The table called localtable does exist in the Access db.  I think the code is trying to put the data in to sql - NOT Access.

 Here is what I have currently:

Dim cnn As ADODB.Connection
Dim rs As ADODB.Recordset
Set cnn = New ADODB.Connection
cnn.ConnectionString = "driver={SQL Server};" & "server=SERVER1;uid=sa;pwd=password;database=ABCD"
cnn.Open
Set rs = cnn.Execute("INSERT INTO localtable SELECT IVC30101.* FROM IVC30101;"
 rs.Close
0
 
LVL 11

Expert Comment

by:mildurait
ID: 24103470
Yep, that's exactly what the code is trying to do (see my original comment).
You need to use the docmd.runsql(sql) after linking the sql table to access to write to a local table in access.
0
 

Author Comment

by:sd854282
ID: 24103523
The SQL table is linked.  The SQL table is linked to the access db that this code is running in.  Localtable is in access.
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 11

Expert Comment

by:mildurait
ID: 24103533
Try
You need to execute the sql locally rather than in the sql database.

call docmd.runsql("INSERT INTO localtable SELECT IVC30101.* FROM IVC30101;")

<The above does get it into the local Access mdb instead of sql.  However, the login issue is still present.>
You need to unlink and link the sql table again ensuring that the remember password option is checked.
0
 

Author Comment

by:sd854282
ID: 24103546
The SQL is executed locally in access through VGA
0
 
LVL 11

Expert Comment

by:mildurait
ID: 24103560
<cnn.ConnectionString = "driver={SQL Server};" & "server=SERVER1;uid=sa;pwd=password;database=ABCD">
Yes VBA is executing the code locally, but the data updates are executed in the ABCD database on the SERVER1 sql server directly, not in access.

You need VBA to maniplulate the local table and the locally linked sql table, which is why you would run docmd.runsql.
0
 

Author Comment

by:sd854282
ID: 24103798
Below are the two options I am currently working with:

1)   Set rs = cnn.Execute("INSERT INTO localtable SELECT IVC30101.* FROM IVC30101;")
2)   Call DoCmd.RunSQL("INSERT INTO localtable SELECT IVC30101.* FROM IVC30101;")

The problem is that option 2 still requires a login.  Even if you tell the odbc connection to remember, the password, it doesn't.  

Any ideas?

0
 
LVL 11

Expert Comment

by:mildurait
ID: 24103817
2) is the correct answer to this question.

<Even if you tell the odbc connection to remember, the password, it doesn't.>
This is a separate issue.  
Suggest asking another question.
0
 
LVL 38

Accepted Solution

by:
Jim P. earned 500 total points
ID: 24106693
Great Plains, in its current design, does not use Windows Authentication.

You can never save the password in a SQL Server ODBC call itself. That was done deliberately by Microsoft for security.

When you link tables you have two options. Using Integrated Security/Windows Authentication or SQL Authentication with a userid and password. Linked tables are using the DAO/JET engine, not the ADO connections.

If you want, you can create a separate Windows Domain userid in a GP DB, but that is done with the SQL Server Management Studio (or similar tools) and GP will totally disregard that userid.

If you use SQL Authentication, when you link the tables in, on the lower right-hand corner is a checkbox to Save Password. Turn it on.

As far as the ADO "rs = cnn.Execute" commands: That is telling the SQL Server to run on the Server side an insert into localtable which probably doesn't exist and that is why you are getting an error and no results. ADO does not know anything about your local tables in Access and can't see them by default.

You need to run the DAO command, something like below to get the data into your local tables
Dim SQL as String
 

SQL = "INSERT INTO localtable " & _

     "SELECT * " & _

     "FROM IVC30101;"
 

DoCmd.SetWarnings False

DoCmd.RunSQL SQL

DoCmd.SetWarnings True

Open in new window

Save-Pwd-Link-Tables.jpg
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

762 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

24 Experts available now in Live!

Get 1:1 Help Now