stud1.bas
来自「VB ACCESSS数据库课程设计」· BAS 代码 · 共 45 行
BAS
45 行
Attribute VB_Name = "stud1"
Option Explicit
Public gstruser As String
Public gblnpurview As Boolean
Public pubcnn As New ADODB.Connection
Public Sub createconnection()
pubcnn.CursorLocation = adUseClient
pubcnn.Open "provider=microsoft.jet.oledb.4.0;data source=student.mdb"
End Sub
'填充班级组合框。参数为组合框对象变量
Public Sub addclassitem(cboX As ComboBox)
Dim rstmp As New ADODB.Recordset '临时记录集
rstmp.Open "select 班级 from 学籍 group by 班级 having 班级<>null and 班级<>''", pubcnn, adOpenStatic, adLockOptimistic
cboX.Clear
Do Until rstmp.EOF
cboX.AddItem rstmp("班级")
rstmp.MoveNext
Loop
Set rstmp = Nothing
End Sub
Public Sub focusback(txtX As TextBox)
With txtX
.SelStart = 0
.SelLength = Len(.Text)
.SetFocus
End With
End Sub
'班级组合框失去焦点时检查列表,若用户输入了新班级,添加新项
Public Sub newclassitem(cboX As ComboBox) '参数为组合框对象变量
Dim i As Integer
Dim blnold As Boolean
Dim snew As String
blnold = False
snew = Trim$(cboX.Text) '取用户在组合框输入的班级名称
For i = 0 To cboX.ListCount - 1
If cboX.List(i) = snew Or snew = "" Then
blnold = True
Exit For
End If
Next
If blnold = False Then '若列表中无该班级名称,添加
cboX.AddItem snew
End If
End Sub
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?