For i = 1 To 12 '添加月份 Combom.AddItem i Next i
For i = 1 To 31 '添加日期 Combod.AddItem i Next i setgrid setgrid_head
Text5.Visible = False clear_grid Exit Sub loaderror:
MsgBox Err.Description End Sub
Private Sub Form_Unload(Cancel As Integer) '关闭数据对象 rs_checkname.Close rs_custom.Close End Sub
Public Sub setgrid() '设置表格子程序 Dim i As Integer On Error GoTo seterror
MSFlexGrid1.ScrollBars = flexScrollBarBoth MSFlexGrid1.FixedCols = 0 MSFlexGrid1.Rows = row_num MSFlexGrid1.Cols = col_num
MSFlexGrid1.SelectionMode = flexSelectionByRow For i = 0 To row_num - 1
MSFlexGrid1.RowHeight(i) = 315 Next
For i = 0 To col_num - 1
MSFlexGrid1.ColWidth(i) = 1300 Next i Exit Sub seterror:
MsgBox Err.Description End Sub
Public Sub setgrid_head() On Error GoTo setheaderror
MSFlexGrid1.Col = 0
MSFlexGrid1.Text = \车辆名称\MSFlexGrid1.Col = 1
MSFlexGrid1.Text = \单价\MSFlexGrid1.Col = 2 MSFlexGrid1.Text = \数量\MSFlexGrid1.Col = 3 MSFlexGrid1.Text = \单位\MSFlexGrid1.Col = 4
MSFlexGrid1.Text = \金额\MSFlexGrid1.Col = 5
MSFlexGrid1.Text = \供应商名称\Exit Sub setheaderror:
MsgBox Err.Description End Sub
Public Sub clear_grid() Dim i As Integer, j As Integer For i = 1 To row_num - 1 MSFlexGrid1.Row = i For j = 0 To col_num - 1 MSFlexGrid1.Col = j MSFlexGrid1.Text = \ Next j Next i End Sub
Public Sub nextposition(ByVal r As Integer, ByVal c As Integer) On Error GoTo nexterror
Text5.Width = MSFlexGrid1.CellWidth Text5.Height = MSFlexGrid1.CellHeight
Text5.Left = MSFlexGrid1.Left + MSFlexGrid1.ColPos(c) Text5.Top = MSFlexGrid1.Top + MSFlexGrid1.RowPos(r) Text5.Text = MSFlexGrid1.Text Text5.Visible = True Text5.SetFocus Exit Sub nexterror:
MsgBox Err.Description End Sub
If Combo1.Visible = True Then Exit Sub End If
nextposition MSFlexGrid1.Row, MSFlexGrid1.Col End Sub
Private Sub Text5_KeyPress(KeyAscii As Integer) Dim i As Integer, j As Integer Dim price As Double, coun As Integer On Error GoTo texterror If KeyAscii = keyenter Then MSFlexGrid1.Text = Text5.Text i = MSFlexGrid1.Row j = MSFlexGrid1.Col
If j = 0 And Trim(Text5.Text) = \
MsgBox \车辆名称不能为空\ Text5.SetFocus Exit Sub End If
If j = 1 And Not IsNumeric(Text5.Text) Then
MsgBox \单价请输入数字!\ Text5.SetFocus Exit Sub End If
If j = 2 And Not IsNumeric(Text5.Text) Then
MsgBox \数量请输入数字!\ Text5.SetFocus Exit Sub End If
If j = 3 And Trim(Text5.Text) = \
MsgBox \单位不能为空!\ Text5.SetFocus Exit Sub End If
If j = 3 And Not IsNull(Text5.Text) Then
MSFlexGrid1.Col = 1 '金额由程序算出 price = CDbl(MSFlexGrid1.Text) MSFlexGrid1.Col = 2
coun = CInt(MSFlexGrid1.Text) MSFlexGrid1.Col = 4
MSFlexGrid1.Text = price * coun
MSFlexGrid1.Col = MSFlexGrid1.Col + 1 Text5.Visible = False
setcombo2 MSFlexGrid1.Row, MSFlexGrid1.Col KeyAscii = 0 Exit Sub End If
MSFlexGrid1.Col = MSFlexGrid1.Col + 1 KeyAscii = 0
nextposition MSFlexGrid1.Row, MSFlexGrid1.Col End If Exit Sub texterror:
MsgBox Err.Description End Sub
Public Sub setcombo2(ByVal r As Integer, ByVal c As Integer) On Error GoTo seterror
Combo1.Width = MSFlexGrid1.CellWidth
Combo1.Left = MSFlexGrid1.Left + MSFlexGrid1.ColPos(c) Combo1.Top = MSFlexGrid1.Top + MSFlexGrid1.RowPos(r) Combo1.Text = MSFlexGrid1.Text Combo1.Visible = True Combo1.SetFocus Exit Sub seterror:
MsgBox Err.Description End Sub
增加用户代码如下:
Private Sub Command1_Click() Dim sql As String
Dim rs_add As New ADODB.Recordset If Trim(Text1.Text) = \
MsgBox \用户名不能为空\ Exit Sub Text1.SetFocus Else
sql = \系统管理\
rs_add.Open sql, conn, adOpenKeyset, adLockPessimistic While (rs_add.EOF = False)
If Trim(rs_add.Fields(0)) = Trim(Text1.Text) Then MsgBox \已有这个用户\ Text1.SetFocus Text1.Text = \ Text2.Text = \ Text3.Text = \ Combo1.Text = \ Exit Sub Else
rs_add.MoveNext End If Wend