📄 module1.bas
字号:
Attribute VB_Name = "Module1"
Option Explicit
Private rs As New ADODB.Recordset
Private strconn As String
Private strsql As String
Private a1 As Integer
Private b1 As Integer
Private rs3 As New ADODB.Recordset
Private strconn3 As String
Private strsql3 As String
Private s1 As String
Private s2 As String
Sub add1()
On Error Resume Next
strconn = "provider=microsoft.jet.oledb.4.0;data source=" & App.Path & "\horse.mdb"
strsql = "select * from horse1"
With rs
If .State = adStateOpen Then
.Close
End If
.ActiveConnection = strconn
.Source = strsql
.LockType = adLockOptimistic
.CursorLocation = adUseClient
.CursorType = adOpenDynamic
.Open
If Form3.Text1.Text = "" Then
MsgBox "编号和姓名是必填字段"
Exit Sub
End If
If Form3.Text2.Text = "" Then
MsgBox "编号和姓名是必填字段"
Exit Sub
End If
If Form3.Text3.Text = "" Then
Form3.Text3.Text = "null"
End If
.AddNew
rs(0) = Form3.Text1.Text
rs(1) = Form3.Text2.Text
rs(2) = Form3.Text3.Text
.Update
End With
Set Form1.DataGrid1.DataSource = rs
Set Form1.Adodc1.Recordset = rs
With Form1.DataGrid1
.Columns(0).Width = 900
.Columns(1).Width = 1600
.Columns(2).Width = 4000
End With
Form1.Adodc1.Caption = "当前记录为:" & Form1.Adodc1.Recordset.AbsolutePosition & "/" & Form1.Adodc1.Recordset.RecordCount
Form3.Text1.Text = ""
Form3.Text2.Text = ""
Form3.Text3.Text = ""
End Sub
Sub add2()
On Error Resume Next
strconn = "provider=microsoft.jet.oledb.4.0;data source=" & App.Path & "\horse.mdb"
strsql = "select * from horse2"
With rs
If .State = adStateOpen Then
.Close
End If
.ActiveConnection = strconn
.Source = strsql
.LockType = adLockOptimistic
.CursorLocation = adUseClient
.CursorType = adOpenDynamic
.Open
If Form4.Text1.Text = "" Then
MsgBox "请填写正确编号"
Exit Sub
End If
If Form4.Text2.Text = "" Then
MsgBox "请填写正确编号"
Exit Sub
End If
If Form4.Text3.Text = "" Then
MsgBox "请填写正确编号"
Exit Sub
End If
If Form4.Combo2.Text = "请选择场次" Then
MsgBox "请选择场次"
Exit Sub
End If
If Form4.Combo2.Text = "第一场" Then
b1 = 1
End If
If Form4.Combo2.Text = "第二场" Then
b1 = 2
End If
If Form4.Combo2.Text = "第三场" Then
b1 = 3
End If
If Form4.Combo2.Text = "第四场" Then
b1 = 4
End If
If Form4.Combo2.Text = "第五场" Then
b1 = 5
End If
If Form4.Combo2.Text = "第六场" Then
b1 = 6
End If
If Form4.Combo2.Text = "第七场" Then
b1 = 7
End If
If Form4.Combo2.Text = "第八场" Then
b1 = 8
End If
If Form4.Combo2.Text = "第九场" Then
b1 = 9
End If
If Form4.Combo2.Text = "第十场" Then
b1 = 10
End If
If Form4.Combo2.Text = "第十一场" Then
b1 = 11
End If
If Form4.Combo2.Text = "第十二场" Then
b1 = 12
End If
If Form4.Combo2.Text = "第十三场" Then
b1 = 13
End If
If Form4.Combo2.Text = "第十四场" Then
b1 = 14
End If
If Form4.Combo2.Text = "第十五场" Then
b1 = 15
End If
.AddNew
rs(0) = Form4.Text1.Text
rs(1) = Form4.Text2.Text
rs(2) = Form4.Combo2.Text
rs(3) = b1
rs(4) = Form4.Text3.Text
.Update
End With
strconn = "provider=microsoft.jet.oledb.4.0;data source=" & App.Path & "\horse.mdb"
strsql = "select 场次,编号,姓名,资料 from horse2"
With rs
If .State = adStateOpen Then
.Close
End If
.ActiveConnection = strconn
.Source = strsql
.LockType = adLockOptimistic
.CursorLocation = adUseClient
.CursorType = adOpenDynamic
.Open
End With
Set Form2.DataGrid1.DataSource = rs
Set Form2.Adodc1.Recordset = rs
With Form2.DataGrid1
.Columns(0).Width = 1500
.Columns(1).Width = 1000
.Columns(2).Width = 1500
.Columns(3).Width = 1500
End With
Form2.Adodc1.Caption = "当前记录为:" & Form2.Adodc1.Recordset.AbsolutePosition & "/" & Form2.Adodc1.Recordset.RecordCount
Form4.Text1.Text = ""
Form4.Text2.Text = ""
Form4.Text3.Text = ""
Form4.Combo2.Text = "请选择场次"
End Sub
Sub xudi()
strconn = "provider=microsoft.jet.oledb.4.0;data source=" & App.Path & "\horse.mdb"
strsql = "select * from horse2"
With rs
If .State = adStateOpen Then
.Close
End If
.ActiveConnection = strconn
.Source = strsql
.LockType = adLockOptimistic
.CursorLocation = adUseClient
.CursorType = adOpenDynamic
.Open
End With
strconn3 = "provider=microsoft.jet.oledb.4.0;data source=" & App.Path & "\horse.mdb"
strsql3 = "select * from horse1"
With rs3
If .State = adStateOpen Then
.Close
End If
.ActiveConnection = strconn3
.Source = strsql3
.LockType = adLockOptimistic
.CursorLocation = adUseClient
.CursorType = adOpenDynamic
.Open
End With
rs3.MoveFirst
Do While Not rs3.EOF
rs.MoveFirst
's1 = ""
'If ((rs3(2) <> Null) Or (rs3(2) <> "")) Then
s1 = rs3(0)
s2 = rs3(2)
rs.MoveFirst
Do While Not rs.EOF
If rs(0) = s1 Then
rs(1) = rs3(1)
rs(0) = s1
rs(4) = s2
End If
rs.MoveNext
Loop
'Else
'rs(1) = rs3(1)
'rs(4) = Null
'End If
rs3.MoveNext
Loop
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -