Dim RecoPrivate Sub Form_Load()
Set conn = CreateObject("ADODB.Connection")
Set Reco = CreateObject("ADODB.Recordset")
conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\sjk.mdb"
Reco.CursorLocation = adUseClient
Reco.Open "Select * From data ", conn, 1, 1Set MSHFlexGrid1.DataSource = RecoDim i As Integer
With MSHFlexGrid1
.Redraw = False
.AllowBigSelection = True ' 设置网格样式
.FillStyle = flexFillRepeat
For i = 1 To .Rows - 1
.Row = i
.Col = .FixedCols
.ColSel = .Cols - .FixedCols
If i Mod 2 = 0 Then '包括标题开始,偶数行白色
.CellBackColor = &HFFFFFF '白色
Else '窗体颜色:&H8000000F
.CellBackColor = &HF0FFF0 '奇数行浅青色
End If
If (.Text) = False And Len(.TextMatrix(i, 4)) > 0 Then
.CellBackColor = &HFF&
End If
Next i
.Redraw = True
End WithEnd Sub
Private Sub btnDown_Click()
If Not Reco.EOF Then
Call showData
'MsgBox (Reco.AbsolutePage)
End If
End SubPrivate Sub btnUp_Click()
If Not Reco.BOF Then
Call showData
'MsgBox (Reco.AbsolutePage)
End If
End SubPrivate Function showData()
Dim i As Integer
Reco.PageSize = 12
With MSHFlexGrid1
.Redraw = False
.Cols = 6
If Reco.RecordCount <= Reco.PageSize Then
.Rows = rs.RecordCount + 1
Else
.Rows = Reco.PageSize + 1
End If
.TextMatrix(0, 1) = "来文字号"
.TextMatrix(0, 2) = "文件标题"
.TextMatrix(0, 3) = "文件日期"
.TextMatrix(0, 4) = "主题词"
.TextMatrix(0, 5) = "存放位置"For i = 1 To (.Rows - 1)
If Not Reco.EOF Then
.TextMatrix(i, 0) = Reco.Fields("入库单编号")
Reco.MoveNext
End If
Next iFor i = 0 To 5
.ColAlignment(i) = 3
Next i
.Redraw = True
End With
End Function
Dim RecoPrivate Sub Form_Load()
Set conn = CreateObject("ADODB.Connection")
Set Reco = CreateObject("ADODB.Recordset")
conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\sjk.mdb"
Reco.CursorLocation = adUseClient
Reco.Open "Select * From data ", conn, 1, 1Reco.pagesize = 12
If Reco.RecordCount > 12 Then
Reco.Move 12
Else
Reco.movelast
End IfSet MSHFlexGrid1.DataSource = RecoDim i As Integer
With MSHFlexGrid1
.Redraw = False
.AllowBigSelection = True ' 设置网格样式
.FillStyle = flexFillRepeat
For i = 1 To .Rows - 1
.Row = i
.Col = .FixedCols
.ColSel = .Cols - .FixedCols
If i Mod 2 = 0 Then '包括标题开始,偶数行白色
.CellBackColor = &HFFFFFF '白色
Else '窗体颜色:&H8000000F
.CellBackColor = &HF0FFF0 '奇数行浅青色
End If
If (.Text) = False And Len(.TextMatrix(i, 4)) > 0 Then
.CellBackColor = &HFF&
End If
Next i
.Redraw = True
End WithEnd Sub
Private Sub btnDown_Click()
If Not Reco.EOF Then
Call showData
'MsgBox (Reco.AbsolutePage)
End If
End SubPrivate Sub btnUp_Click()
If Not Reco.bof Then
Reco.Move -Reco.pagesize * 2
Call showData
'MsgBox (Reco.AbsolutePage)
End If
End SubPrivate Function showData()
Dim i As Integer
With MSHFlexGrid1
.Redraw = False
.Cols = 6
If Reco.RecordCount <= Reco.PageSize Then
.Rows = rs.RecordCount + 1'????
Else
.Rows = Reco.PageSize + 1
End If
.TextMatrix(0, 1) = "来文字号"
.TextMatrix(0, 2) = "文件标题"
.TextMatrix(0, 3) = "文件日期"
.TextMatrix(0, 4) = "主题词"
.TextMatrix(0, 5) = "存放位置"If Reco.bof Then Reco.movefirst
For i = 1 To (.Rows - 1)
If Not Reco.EOF Then
.TextMatrix(i, 0) = Reco.Fields("入库单编号")
Reco.MoveNext
End If
Next iFor i = 0 To 5
.ColAlignment(i) = 3
Next i
.Redraw = True
End With
End Function
.Redraw = False
.Rows = 13'你的是否在属性里设置成了13?
.AllowBigSelection = True ' 设置网格样式
.FillStyle = flexFillRepeat
For i = 1 To .Rows - 1
.Row = i
.Col = .FixedCols
.ColSel = .Cols - .FixedCols
If i Mod 2 = 0 Then '包括标题开始,偶数行白色
.CellBackColor = &HFFFFFF '白色
Else '窗体颜色:&H8000000F
.CellBackColor = &HF0FFF0 '奇数行浅青色
End If
If (.Text) = False And Len(.TextMatrix(i, 4)) > 0 Then
.CellBackColor = &HFF&
End If
Next i
.Redraw = True
End With
.TextMatrix(i, 1) = Reco.Fields("供应商编号")
.TextMatrix(i, 2) = Reco.Fields("发票号码")
.TextMatrix(i, 3) = Reco.Fields("物料编号")
.TextMatrix(i, 4) = Reco.Fields("物料名称")
.TextMatrix(i, 5) = Reco.Fields("物料规格")
.TextMatrix(i, 0) = Reco.Fields(字段索引).name
如
.TextMatrix(i, 0) = Reco.Fields(0).name
.TextMatrix(i, 0) = Reco.Fields(3).name
等
Set conn = CreateObject("ADODB.Connection")
Set Reco = CreateObject("ADODB.Recordset")
conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\sjk.mdb"
Reco.CursorLocation = adUseClient
Reco.Open "Select * From data ", conn, 1, 1
Reco.PageSize = 12
Reco.AbsolutePage = 1Set MSHFlexGrid1.DataSource = RecoDim i As Integer
With MSHFlexGrid1
.Redraw = False
.AllowBigSelection = True ' 设置网格样式
.FillStyle = flexFillRepeat
For i = 1 To .Rows - 1
.Row = i
.Col = .FixedCols
.ColSel = .Cols - .FixedCols
If i Mod 2 = 0 Then '包括标题开始,偶数行白色
.CellBackColor = &HFFFFFF '白色
Else '窗体颜色:&H8000000F
.CellBackColor = &HF0FFF0 '奇数行浅青色
End If
If (.Text) = False And Len(.TextMatrix(i, 4)) > 0 Then
.CellBackColor = &HFF&
End If
Next i
.Redraw = True
End WithEnd SubPrivate Sub btnDown_Click()
If Reco.AbsolutePage < Reco.PageCount Then
Reco.AbsolutePage = Reco.AbsolutePage + 1
Call showData
'MsgBox (Reco.AbsolutePage)
End If
End SubPrivate Sub btnUp_Click()
If Reco.AbsolutePage > 1 Then
Reco.AbsolutePage = Reco.AbsolutePage - 1
Call showData
'MsgBox (Reco.AbsolutePage)
End If
End Sub
按理说,你已经把 MSHFlexGrid 绑定到记录集,不需要人工填写单元格。去掉试试。
......
......
Reco.pagesize = 12
If Reco.RecordCount > 12 Then
Reco.Move 12
Else
Reco.movelast
End IfDim i As Integer
With MSHFlexGrid1
.FixedRows = 1
.FixedCols = 1
Set .DataSource = Reco
.Rows = 13
.Redraw = False
.AllowBigSelection = True ' 设置网格样式
.FillStyle = flexFillRepeat
For i = 1 To .Rows - 1
.Row = i
.Col = .FixedCols
.ColSel = .Cols - .FixedCols
If i Mod 2 = 0 Then '包括标题开始,偶数行白色
.CellBackColor = &HFFFFFF '白色
Else '窗体颜色:&H8000000F
.CellBackColor = &HF0FFF0 '奇数行浅青色
End If
.....
.....以下部分注掉所有标题部分:Private Function showData()
Dim i As Integer
With MSHFlexGrid1
.Redraw = False
.Cols = 6
If Reco.RecordCount <= Reco.pagesize Then
.Rows = rs.RecordCount + 1
Else
.Rows = Reco.pagesize + 1
End If
'.TextMatrix(0, 1) = "来文字号"'这一部分注掉
'.TextMatrix(0, 2) = "文件标题"
'.TextMatrix(0, 3) = "文件日期"
'.TextMatrix(0, 4) = "主题词"
'.TextMatrix(0, 5) = "存放位置"
If Reco.bof Then Reco.movefirst
For i = 1 To (.Rows - 1)
................
................
.TextMatrix(i, 0) = Reco.Fields("入库单编号")
.TextMatrix(i, 1) = Reco.Fields("供应商编号")
.TextMatrix(i, 2) = Reco.Fields("发票号码")
.TextMatrix(i, 3) = Reco.Fields("物料编号")
.TextMatrix(i, 4) = Reco.Fields("物料名称")
.TextMatrix(i, 5) = Reco.Fields("物料规格")
for j=0 to mshflexgrid1.cols-1
.TextMatrix(i, j) = Reco(j)
next或
for i=0 to .recordset.fields.count-1
...next
Dim RecoPrivate Sub Form_Load()
Set conn = CreateObject("ADODB.Connection")
Set Reco = CreateObject("ADODB.Recordset")
conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\sjk.mdb"
Reco.CursorLocation = adUseClient
Reco.Open "Select * From data ", conn, 1, 1Reco.PageSize = 12
If Reco.RecordCount > 12 Then
Reco.Move 12
Else
Reco.MoveLast
End IfSet MSHFlexGrid1.DataSource = RecoDim i As Integer
With MSHFlexGrid1
.FixedRows = 1
.FixedCols = 1
Set .DataSource = Reco
.Rows = 13
.Redraw = False
.Rows = 13
.AllowBigSelection = True ' 设置网格样式
.FillStyle = flexFillRepeat
For i = 1 To .Rows - 1
.Col = .FixedCols
.ColSel = .Cols - .FixedCols
If i Mod 2 = 0 Then '包括标题开始,偶数行白色
.CellBackColor = &HFFFFFF '白色
Else '窗体颜色:&H8000000F
.CellBackColor = &HF0FFF0 '奇数行浅青色
End If
If (.Text) = False And Len(.TextMatrix(i, 4)) > 0 Then
.CellBackColor = &HFF&
End If
Next i
.Redraw = True
End With
Call AdjustColWidth(Form1, MSHFlexGrid1)
End Sub
Private Sub btnDown_Click()
If Not Reco.EOF Then
Call showData
'MsgBox (Reco.AbsolutePage)
End If
End SubPrivate Sub btnUp_Click()
If Not Reco.BOF Then
Reco.Move -Reco.PageSize * 2
Call showData
'MsgBox (Reco.AbsolutePage)
End If
End SubPrivate Function showData()
Dim i As Integer
With MSHFlexGrid1
.Redraw = False
.Cols = 6If Reco.RecordCount <= Reco.PageSize Then
.Rows = rs.RecordCount + 1 '????
Else
.Rows = Reco.PageSize + 1
End If
'.TextMatrix(0, 0) = Reco.Fields(0).Name
'.TextMatrix(0, 1) = Reco.Fields(1).Name
'.TextMatrix(0, 2) = Reco.Fields(2).Name
'.TextMatrix(0, 3) = Reco.Fields(3).Name
'.TextMatrix(0, 4) = Reco.Fields(4).Name
'.TextMatrix(0, 5) = Reco.Fields(5).NameIf Reco.BOF Then Reco.MoveFirst
For i = 1 To (.Rows - 1)
If Not Reco.EOF Then
'.TextMatrix(i, 0) = Reco.Fields("入库单编号")
'.TextMatrix(i, 1) = Reco.Fields("供应商编号")
'.TextMatrix(i, 2) = Reco.Fields("发票号码")
'.TextMatrix(i, 3) = Reco.Fields("物料编号")
'.TextMatrix(i, 4) = Reco.Fields("物料名称")
'.TextMatrix(i, 5) = Reco.Fields("物料规格")
For j = 0 To MSHFlexGrid1.Cols - 1
.TextMatrix(i, j) = Reco(j)
NextReco.MoveNext
End If
Next iFor i = 0 To 3
.ColAlignment(i) = 3
Next i
.Redraw = True
End With
Call AdjustColWidth(Form1, MSHFlexGrid1)End Function
Dim i As Integer
With MSHFlexGrid1
.Redraw = False
.Cols = 6
这行删除就行了。
.TextMatrix(i, j) = Reco(j) & ""隔行颜色问题自己再看看吧。