Dim i As Integer
Dim MsgText As String
‘获得数据集
Set mrc = ExecuteSQL(txtSQL, MsgText)
With msgList
.Rows = 1
‘判断是否为空
Do While Not mrc.EOF
‘移动到下一行
.Rows = .Rows + 1
‘循环
For i = 1 To mrc.Fields.Count
‘判断是否为空
If Not IsNull(Trim(mrc.Fields(i - 1))) Then
‘根据数据类型显示
Select Case mrc.Fields(i - 1).Type
Case adDBDate
.TextMatrix(.Rows - 1, i) = Format(mrc.Fields(i - 1) & "", "yyyy-mm-dd")
Case Else
.TextMatrix(.Rows - 1, i) = mrc.Fields(i - 1) & ""
End Select
End If
Next I
‘移动到下一条记录
mrc.MoveNext
Loop
End With
‘关闭数据集对象
mrc.Close
End Sub
在窗体显示时,可以控制窗体中各个控件按照要求的位置显示。可以在窗体的Resize事件中加入代码,代码如下:
Private Sub Form_Resize()
‘判断当前窗体所处的状态,当前窗体不处于最小化状态并且主窗体不处于最小化状态时进行后面的操作
If Me.WindowState <> vbMinimized And fMainForm.WindowState <> vbMinimized Then
'边界处理
If Me.ScaleHeight < 10 * lblTitle.Height Then
Exit Sub
End If
If Me.ScaleWidth < lblTitle.Width + lblTitle.Width / 2 Then
Exit Sub
End If
'控制控件的位置
lblTitle.Top = lblTitle.Height
lblTitle.Left = (Me.Width - lblTitle.Width) / 2
‘控制表格控件的位置
msgList.Top = lblTitle.Top + lblTitle.Height + lblTitle.Height / 2
msgList.Width = Me.ScaleWidth - 200
msgList.Left = Me.ScaleLeft + 100
msgList.Height = Me.ScaleHeight - msgList.Top - 1500
‘控制按钮位置
Frame2.Top = msgList.Top + msgList.Height + 50
Frame2.Left = Me.ScaleWidth / 2 - 3000
End If
End Sub
6.2 添加舱位信息窗体的创建
在舱位信息显示窗体中单击“添加”按钮,将出现如图9-13所示的窗体。
图9-13 添加舱位等级信息窗体
载入窗体时,首先根据标志变量判断状态,然后决定是添加还是修改,代码如下:
Private Sub Form_Load()
Dim intCount As Integer
Dim MsgText As String
Dim i As Integer
‘判断是否为添加
If gintSmode = 1 Then
Me.Caption = Me.Caption & "添加"
For i = 0 To 7
Combo1(i).AddItem "否"
Combo1(i).AddItem "是"
Combo1(i).ListIndex = 0
Next I
‘载入当前选择记录内容
ElseIf gintSmode = 2 Then
Set mrc = ExecuteSQL(txtSQL, MsgText)
‘判断记录是否为空
If mrc.EOF = False Then
With mrc
For intCount = 0 To 1
txtItem(intCount) = .Fields(intCount)
Next intCount
txtItem(2) = .Fields(10)
For i = 0 To 7
Combo1(i).AddItem "否"
Combo1(i).AddItem "是"
Combo1(i).ListIndex = 0
Next i
End With
txtItem(0).Enabled = False
End If
Me.Caption = Me.Caption & "修改"
End If
mblChange = False
End Sub
输入内容完毕,单击“保存”按钮,将首先判断输入内容是否满足要求,然后添加到数据库中。代码如下:
Private Sub cmdSave_Click()
Dim intCount As Integer
Dim sMeg As String
Dim MsgText As String
‘判断输入内容是否为空
For intCount = 0 To 1
If Trim(txtItem(intCount) & " ") = "" Then
Select Case intCount
Case 0
sMeg = "机舱等级编号"
Case 1
sMeg = "机舱等级名称"
End Select
sMeg = sMeg & "不能为空!"
MsgBox sMeg, vbOKOnly + vbExclamation, "警告"
txtItem(intCount).SetFocus
Exit Sub
End If
上一页 [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] ... 下一页 >>