Académique Documents
Professionnel Documents
Culture Documents
Open "Provider=sqloledb;Data Source=SSST41;Initial Catalog=sample;User ID=sa;Password=;" str = "select name from stutable" rs.Open str, con i=0 While Not rs.EOF Combo1.List(i) = rs.Fields(0) rs.MoveNext i=i+1 Wend rs.Close Dim con As New ADODB.Connection Dim rs As New ADODB.Recordset Dim i As Integer con.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\\Asm-isntcasus\database\mast.mdb;Persist Security Info=False" str = "select Name from mast" rs.Open str, con i=0 While Not rs.EOF Combo3.List(i) = rs.Fields(0) rs.MoveNext i=i+1 Wend rs.Close
Code: Dim total1 For i = 0 To MSHFlexgrid1.Rows - 1 MSHFlexgrid1.Row = i MSHFlexgrid1.Col = 4 total1 = Val(total1) + Val(MSHFlexgrid1.Text) Next
If MsgBox("Do you really want to delete this
record", vbYesNo) = vbYes Then Set cn = New ADODB.Connection sConnection = <="" span="" style="margin: 0px; padding: 0px; border: 0px; outline: 0px; font-size: 12px; backgroundcolor: transparent; background-position: initial initial; background-repeat: initial initial; "> cn.Open sConnection Set cmd.ActiveConnection = cn I = MSFlexGrid1.RowSel MSFlexGrid1.RemoveItem I End If
Private Sub HoverCommand2_Click() Dim cn As ADODB.Connection Dim sConnection As String Dim cmd As New ADODB.Command Dim strQuery As String Dim rsRecordSet As Recordset
End Sub
Dim excel_app As Object Dim excel_sheet As Object Dim max_row As Double Dim max_col As Integer Dim Excel_row As Double Dim Excel_Col As Integer Dim xl As New excel.Application Dim xlWB As New excel.Workbook Dim xlWH As New excel.Worksheet Dim i As Integer, Column As Integer, j As Integer Dim conn As ADODB.Connection Dim statement As String Dim new_value As String, new_value1 As String Dim file_path As String Dim FileName As String Dim colvalue As String, colname As String, tempvalue As String Dim Grid_row As Integer, Grid_col As Integer Dim xls As Variant If txtFilePath = "" Then MsgBox "Please first select the excel file!!" cmdBrowse.SetFocus Else file_path = txtFilePath.Text Set excel_app = CreateObject("Excel.Application") excel_app.Workbooks.Open.Text If Val(excel_app.Application.Version) >= 8 Then Set excel_sheet = excel_app.ActiveSheet Else Set excel_sheet = excel_app End If max_row = excel_sheet.UsedRange.Rows.Count max_col = excel_sheet.UsedRange.Columns.Count Screen.MousePointer = vbHourglass
Next
DoEvents flxGrd.Clear flxGrd.Rows = 2 RowCNT = 0 ColCNT = 0 'first loop for rows For i = 1 To max_row 'second loop for columns For j = 1 To max_col With flxGrd .TextMatrix(i - 1, j - 1) = _ excel_sheet.Cells(i, j).Value & " " End With Next
Public Function PopulateFlexGrid(FlexGrid As Object, _ rs As Object) As Boolean '******************************************************* 'PURPOSE: Populate MSFlexGrid with data from an ' ADO Recordset
'PARAMETERS: FlexGrid: MsFlexGrid to Populate ' RS: Open ADO Recordset 'RETURNS: True if successful, false otherwise 'REQUIRES: -- Reference to Microsoft Active Data Objects ' -- Recordset should be open with cursor set at ' first row when passed and must ' support recordcount property ' -- FlexGrid should be empty when passed 'EXAMPLE: 'Dim conn As New ADODB.Connection 'Dim rs As New ADODB.Recordset 'Dim sConnString As String ' 'sConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\MyDatabase.mdb" 'conn.Open sConnString 'rs.Open " SELECT * FROM MyTable", oConn, adOpenKeyset, adLockOptimistic 'PopulateFlexGrid MSFlexGrid1, rs ' 'rs.Close 'conn.Close '*********************************************************** On Error GoTo ErrorHandler If Not TypeOf FlexGrid Is MSFlexGrid Then Exit Function If Not TypeOf rs Is ADODB.Recordset Then Exit Function Dim i As Integer Dim J As Integer FlexGrid.FixedRows = 1 FlexGrid.FixedCols = 0 If Not rs.EOF Then FlexGrid.Rows = rs.RecordCount + 1 FlexGrid.Cols = rs.Fields.Count
Do While Not rs.EOF For J = 0 To rs.Fields.Count - 1 If Not IsNull(rs.Fields(J).Value) Then FlexGrid.TextMatrix(i, J) = _ rs.Fields(J).Value End If Next i=i+1 rs.MoveNext Loop End If PopulateFlexGrid = True ErrorHandler: Exit Function End Function
Let's try this code.. I've been using it and it works excellent!!
1. Private Sub cmdPrint_Click() 2. 'Print the grid with the top row as a title row 3. FlexGridPrint Me.Grd, , , , , 1
4. End Sub
3.
4.
5. 6. 7. 8. 9. 10. 11. On Error GoTo ErrFailed Grd.TopRow = 1 lNumRows = Grd.Rows - 1 lPrinterPageHeight = Printer.Height lRowsPerPage = lMaxRowsPerPage lRowsPrinted = lRowsToRepeat
12.
13. 14. 15. 16. 17. 18. If lRowsToRepeat Then 'Calculate the height of the heading row For lThisRow = 1 To lRowsToRepeat lHeadingHeight = lHeadingHeight + Grd.RowHeight(lThisRow) Next End If
19.
20. 21. 22. 23. 24. 25. Do 'Calculate the number of rows for this page lImageHeight = 0 lRowsPerPage = 0 'Setup printer Printer.Orientation = lOrientation
26.
27. 28. 29. Then 30. 'Image has required number of rows, subtract height of current row For lThisRow = lRowsPrinted To lNumRows lImageHeight = lImageHeight + Grd.RowHeight(lThisRow) If lRowsPerPage > lMaxRowsPerPage And lMaxRowsPerPage <> -1
lImageHeight = lImageHeight - Grd.RowHeight(lThisRow) Exit For ElseIf lImageHeight + lTopBorder * 2 + lHeadingHeight > lPrinterPageHeight Then 'Allow the same border at the bottom and top
34. 35. 36. 37. 38. 39. 40. 41. 42. 43. 44. 45.
'Image is larger than page, subtract height of current row lImageHeight = lImageHeight - Grd.RowHeight(lThisRow) Exit For End If lRowsPerPage = lRowsPerPage + 1 Next
'Print this page lPagesPrinted = lPagesPrinted + 1 If lRowsToRepeat Then 'Print heading rows Printer.PaintPicture Grd.Picture, lLeftBorder, lTopBorder, , lHeadingHeight, , 0, , lHeadingHeight
46. 47.
'Print data rows Printer.PaintPicture Grd.Picture, lLeftBorder, lTopBorder + lHeadingHeight, , lImageHeight + lHeadingHeight, , lLastImageTop + lHeadingHeight, , lImageHeight + lHeadingHeight
Else 'Print data rows Printer.PaintPicture Grd.Picture, lLeftBorder, lTopBorder, , lImageHeight, , lLastImageTop, , lImageHeight
End If
Printer.EndDoc
FlexGridPrint = True
Exit Function
65. ErrFailed: 66. 67. 68. 'Failed to print grid FlexGridPrint = False Debug.Print "Error in FlexGridPrint: " & Err.Description
69.
70. End Function