i cant print selected rows in datagrid so now i have to export the selected rows in excel file so in that way i can print the selected rows..thanx

 Sheet2.Range("A16:M20").PrintOut

I haven't used a DataGrid in 12 years and I didn't load Access on this computer, but I did some research for you.

I find no way to pring directly from the DataGrid.

However if you can get the data into something that can be printed, like Excel, then printing is much easier.

My last post will print form excel.
The question the follows: How do you get DataGrid to Excel?
This thread seems to handle that task.
The following is vb6 code that will print the range A1 to D5, tested and works.

Private Sub Print_cmd_Click()
Dim xl As New Excel.Application
Dim wbkdes As Workbook
Dim wsToPrint As Worksheet
    Set wbkdes = xl.Workbooks.Open("C:\YourPath\YourWorkBook.xls")
    Set wsToPrint = wbkdes.ActiveSheet
    With wsToPrint
        .Range("A1:D5").PrintOut
    End With
    wbkdes.Close True
    xl.Quit
    Set xl = Nothing
    Set wbkdes = Nothing
    Set wsToPrint = Nothing
    MsgBox "Data Sent to Printer"
End Sub

You may have to format column width in YourWorkBook
Regards

thanx for the help sir.i will try this code that u gave me..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.