Macro to extract data

Excel Vba for Sage

Macro to extract data

Postby ben_wood » Mon May 14, 2007 2:15 pm

How can you use a macro to extract data out of MMS version 2.2?
ben_wood
 
Posts: 17
Joined: Mon May 14, 2007 1:58 pm

Postby freda » Wed May 16, 2007 9:23 am

Yes anyone can help That would be cool

Thanks :)
freda
 
Posts: 6
Joined: Thu Apr 19, 2007 11:04 am

Postby edbeeny » Wed May 16, 2007 10:54 am

A good place to start would be

http://support.microsoft.com/kb/257819

:D
User avatar
edbeeny
 
Posts: 105
Joined: Mon Nov 27, 2006 8:24 pm

Postby edbeeny » Wed May 16, 2007 11:14 am

Try this

Sage Line 500 to extract distinct product and description out of stockm table
Go into Excel F11 and paste this code into the Module
Change the required to fit your network


Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset

Sub get_data()

'Change Server to the server Ip Address
'Change uid to the user Name
'Change pwd to the Password


cn.Open "Driver={SQL Server};" & "Server=127.0.0.1;" & "Database=demo;" & "Uid=User_Name;" & "Pwd=Password;"

sql = "Select distinct product, long_description " _
& "from scheme.stockm"

rs.Open sql, cn

Do Until rs.EOF
Range("A1").CopyFromRecordset rs
Loop

Range("A1").Select

rs.Close
cn.Close

End Sub
User avatar
edbeeny
 
Posts: 105
Joined: Mon Nov 27, 2006 8:24 pm

Postby edbeeny » Wed May 16, 2007 3:17 pm

Sorry I forgot to add you must add Microsoft Activex Data object 2.5 Library

In VBA editor go Tools, References and check the Data object
User avatar
edbeeny
 
Posts: 105
Joined: Mon Nov 27, 2006 8:24 pm

Postby ben21 » Tue Jun 05, 2007 9:27 am

Nice bit of code..

Have you got an example to insert into SQL?

I take it you could develop these simular to Codis's Products..
but make them open source!! :D
ben21
 
Posts: 7
Joined: Tue Apr 24, 2007 3:20 pm

Postby fred_ward » Thu Sep 20, 2007 10:41 am

Could this be adapted for Sage 200?
fred_ward
 
Posts: 2
Joined: Thu Sep 20, 2007 10:35 am

Sage 200

Postby MikeCTerry » Mon May 05, 2008 9:37 am

This was tested with v5

Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset

Sub get_data()

'Change Server to the server Ip Address
'Change uid to the user Name
'Change pwd to the Password


cn.Open "Driver={SQL Server};" & "Server=127.0.0.1;" & "Database=demo;" & "Uid=User_Name;" & "Pwd=Password;"

Sql = "Select Code, Name from StockItem"

rs.Open Sql, cn

Do Until rs.EOF
Range("A1").CopyFromRecordset rs
Loop

Range("A1").Select

rs.Close
cn.Close

End Sub
MikeCTerry
 
Posts: 1
Joined: Mon May 05, 2008 9:01 am

Re: Macro to extract data

Postby or-8 » Fri Nov 21, 2008 11:45 am

Assuming that MMS v2.2 runs on a SQL server.....

Why would you want to use a macro to extract the data?
Can you not just link to the relevant tables using ODBC and extract it that way?

Gordon
OR-8
User avatar
or-8
 
Posts: 31
Joined: Fri Sep 05, 2008 11:07 am

Re: Macro to extract data

Postby freda » Mon Nov 24, 2008 8:50 am

I find problems with ODBC that for complex reports it locks the tables.

With VBA you can be much clever and use dirty reads, and use recordsets within excel to place the data where ever you want to on the Excel sheet.

I would always use VBA over ODBC.
freda
 
Posts: 6
Joined: Thu Apr 19, 2007 11:04 am


Return to Excel Vba



Who is online

Users browsing this forum: No registered users and 1 guest

cron