KeyAscii = 0 End If End Sub
Private Sub txtOpID_KeyPress(KeyAscii As Integer)
If Not (KeyAscii >= vbKey0 And KeyAscii <= vbKey9 _ Or KeyAscii = vbKeyBack) Then KeyAscii = 0 End If End Sub
学生登记界面如图5.4所示。
图5.4学生信息登记界面
代码如下:
Private Sub cmdAdd_Click() dgdVip.Enabled = False cmdRefresh.Enabled = False txtVipID.Enabled = True
If cmdAdd.Caption = \添加(&A)\ cmdAdd.Caption = \确定\ txtVipID.SetFocus
SetTextEmpty ' Reference a founction to set empty cmdDel.Enabled = False
28
cmdModify.Enabled = False cmdRefresh.Enabled = False Else
'To Progress option Dim vipsex As String
If VipMale.Value = True Then vipsex = \男\
ElseIf VipFemale.Value = True Then vipsex = \女\ Else
vipsex = \ End If
If txtVipName.Text = \
MsgBox \ txtVipName.SetFocus Exit Sub
ElseIf txtVipID.Text = \
MsgBox \ txtVipID.SetFocus Exit Sub Else
With objRs
checkAddNew = True
.Filter = \ If .RecordCount > 0 Then
MsgBox \ txtVipID.Text = \ txtVipID.SetFocus .Filter = \ cmdRefresh.Value = True checkAddNew = False cmdDel.Enabled = True cmdModify.Enabled = True cmdAdd.Caption = \添加(&A)\ txtVipID.Enabled = False cmdRefresh.Enabled = True dgdVip.Enabled = True checkAddNew = False Exit Sub End If
checkAddNew = True .AddNew
29
.Fields(0).Value = Trim(txtVipID) .Fields(1).Value = Trim(txtVipName) .Fields(2) = vipsex
.Fields(3) = Trim(txtVipID_card.Text) .Fields(4) = Trim(txtVipPhone.Text) .Fields(5) = Trim(txtVipAddress.Text) .Fields(6) = Trim(txtVipAddTime.Text) .Fields(7) = Trim(txtVipEndTime.Text) .Update
MsgBox \ .Filter = \ cmdRefresh.Value = True End With
checkAddNew = False cmdDel.Enabled = True cmdModify.Enabled = True cmdAdd.Caption = \添加(&A)\ txtVipID.Enabled = False cmdRefresh.Enabled = True dgdVip.Enabled = True End If End If End Sub
Private Sub cmdClose_Click() Unload Me End Sub
Private Sub cmdDel_Click()
If Empty_Check = True Then Exit Sub 'Reference function to check if your database is empty CheckConnect 'To break objrs if it is opened If ConnectToServer = True Then
Set objRs = New ADODB.Recordset
StrSql = \* from tBorrow where cVipID ='\& Trim(txtVipID.Text) & \cReturnTime='' \
GetData StrSql 'Reference function to get data If objRs.RecordCount > 0 Then
MsgBox \ CheckConnect 'To break objrs if it is opened If ConnectToServer = True Then
Set objRs = New ADODB.Recordset StrSql = \
GetData StrSql 'Reference fuction to get data Set dgdVip.DataSource = objRs
30
cmdRefresh.Value = True 'Exectue refresh in order to list data when form load ColNamechange 'Reference fuction to change columns name to chinese End If Else
If MsgBox(txtVipName & \'s data will delete are you sure to continue ?\vbYesNo + vbInformation) = vbYes Then
StrSql = \ objCon.Execute StrSql
CheckConnect 'To break objrs if it is opened If ConnectToServer = True Then
Set objRs = New ADODB.Recordset StrSql = \
GetData StrSql 'Reference function in order to get data Set dgdVip.DataSource = objRs
cmdRefresh.Value = True 'Exectue refresh in order to list data when form load ColNamechange 'Reference fuction to change columns name to chinese End If End If
CheckConnect 'To break objrs if it is opened If ConnectToServer = True Then
Set objRs = New ADODB.Recordset StrSql = \
GetData StrSql 'Reference fuction to get data Set dgdVip.DataSource = objRs
cmdRefresh.Value = True 'Exectue refresh in order to list data when form load ColNamechange 'Reference fuction to change columns name to chinese End If End If End If End Sub
Private Sub cmdModify_Click()
If Empty_Check = True Then Exit Sub 'Reference function to check is your database is empty If Trim(txtVipID.Text) <> Trim(objRs.Fields(0).Value) Then Exit Sub 'To check vipID If cmdModify.Caption = \修改(&M)\ cmdModify.Caption = \确定\ cmdDel.Enabled = False cmdAdd.Enabled = False cmdRefresh.Enabled = False Else
If MsgBox(\you sure to modify this record \vbYesNo + vbInformation) = vbYes Then
With objRs
31
If Not .EOF And .RecordCount > 0 Then .Fields(0).Value = Trim(txtVipID.Text) .Fields(1).Value = Trim(txtVipName.Text) ' .Fields(2) = vipsex
.Fields(3) = Trim(txtVipID_card.Text) .Fields(4) = Trim(txtVipPhone.Text) .Fields(5) = Trim(txtVipAddress.Text) .Fields(6) = Trim(txtVipAddTime.Text) .Fields(7) = Trim(txtVipEndTime.Text) .Update End If End With
cmdModify.Caption = \修改(&M)\ cmdDel.Enabled = True cmdAdd.Enabled = True cmdRefresh.Enabled = True End If End If End Sub
Private Sub cmdRefresh_Click()
RefreshVip 'Reference refreshvip function to refresh End Sub
Private Sub dgdVip_RowColChange(LastRow As Variant, ByVal LastCol As Integer) If checkAddNew = True Then Exit Sub cmdRefresh.Value = True End Sub
Private Sub Form_Activate()
FormMiddle frmVipReg 'Reference function to make form in MDIForm'mddile If ConnectToServer = True Then
Set objRs = New ADODB.Recordset StrSql = \
GetData StrSql 'Reference function in order to get data Set dgdVip.DataSource = objRs
cmdRefresh.Value = True 'Exectue refresh in order to list data when form load ColNamechange 'Reference fuction to change columns name to chinese End If End Sub
图书信息登记界面如图5.5所示。
32