Saturday, March 30, 2013

How to Save a PDF to a SQL Server

http://www.ehow.com/how_7334919_save-pdf-sql-server.html

Wednesday, March 13, 2013

How to select cells/ranges by using Visual Basic procedures in Excel

ActiveSheet.Cells(5, 4).Select  
or 

  
ActiveSheet.Range("D5").Select  

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

Excel VBA ComboBox Populate dynamic value

Private Sub UserForm_Click()
With ComboBox1
For Row = 1 To 10 'Each cell in the range
If ActiveSheet.Cells(2, Row) <> "" Then
.AddItem ActiveSheet.Cells(2, Row)
End If
Next Row
End With


ActiveSheet.Cells(5, 5) = ComboBox1.Value

End Sub

Tuesday, March 5, 2013

Write A Report in Excel using VBA - SQL-server

I wrote first report in Excel-VBA using data from SQL-Server 


Sub runreports()


    

    Dim cnt As ADODB.Connection

    Dim rst As ADODB.Recordset

    Dim stSQL As String

    Dim wbBook As Workbook

    Dim wsSheet As Worksheet

    Dim rnStart As Range

    

     

    Const stADO As String = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=True;Initial Catalog=xxxxx;Data Source=devDB;User ID=myuser;Password=mypass; Use Procedure for Prepare=1;Auto Translate=True;Packet Size=4096;Workstation ID=myPC;Use Encryption for Data=False;Tag with column collation when possible=False"

    

     

    Set wbBook = ActiveWorkbook

    Set wsSheet = wbBook.Worksheets(5)

    

    With wsSheet

        Set rnStart = .Range("A7")

    End With

    'Report Name

    Cells(1, 10).Value = "Interco Report"

    

    stSQL = "SELECT top 100 * FROM tbl_intercoRep"

    'stSQL = "SP_Int_DeleteThis"

'    stSQL = "SP_IntercoReport"

   

     

    Set cnt = New ADODB.Connection

    

    With cnt

        .CursorLocation = adUseClient

        .Open stADO

        .CommandTimeout = 0

        Set rst = .Execute(stSQL)

    End With

   

'Worksheets("sheet5").Activate

Dim ii As Integer

    For ii = 0 To rst.Fields.Count - 1

    Cells(6, ii + 1).Value = rst.Fields(ii).Name

Next ii

 

    With Range("A1:ZZ1").Font

    .Bold = True

    .Size = 15

   

    End With

   

    With Range("A6:ZZ6").Font

    .Bold = True

   

    

    End With

   

     'Here we add the Recordset to the sheet from A1

    rnStart.CopyFromRecordset rst

    

     'Cleaning up.

    rst.Close

    cnt.Close

    Set rst = Nothing

    Set cnt = Nothing

End Sub


Saturday, March 2, 2013

Building a Word Document Using SQL Server Data

In this walkthrough, you will first create a Microsoft® Office Word 2003 document that contains bookmarks as the location for inserting text retrieved from the Microsoft SQL Server Northwind sample database. You will then use ADO.NET to connect to and retrieve the data. You'll insert the data in the Word document at the specified bookmark.

http://msdn.microsoft.com/en-us/library/office/aa192487(v=office.11).aspx