Solved

Pulling Great Plains odbc connected tables into Access

Posted on 2009-04-03
12
1,042 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 

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
 
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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

Desired Skill Set for Microsoft Dynamics CRM Technical Resources – Part I
In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

717 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