我的意思是这样的
在form窗体里有:
command控件数组index=0 to 3
它的单击是件
select case index
case 0
.
.
.
end select
然而红色这部分我想在模块里作一个公共的功能...请问要怎么做...谢谢!
[此贴子已经被作者于2007-1-10 11:40:48编辑过]
Public Function Command11(Command1 As CommandButton, ind As Integer, datPrimaryRS As Adodc, frmMain As Form)
Select Case ind
Case 0 '移到第一条
On Error GoTo err3021
Command1(0).Enabled = False
Command1(3).Enabled = True
Command1(2).Enabled = True
frmMain.datPrimaryRS.Recordset.MoveFirst
err3021:
If Err.Number = 3021 Then
MsgBox "数据库没有数据", vbInformation, "移动出错..."
End If
Case 1 '移到上一条
On Error GoTo err30211
If frmMain.datPrimaryRS.Recordset.AbsolutePosition = adPosBOF Then
Command1(1).Enabled = False
Else
Command1(2).Enabled = True
Command1(0).Enabled = True
Command1(3).Enabled = True
frmMain.datPrimaryRS.Recordset.MovePrevious
End If
err30211:
If Err.Number = 3021 Then
MsgBox "数据库没有数据", vbInformation, "移动出错..."
End If
Case 2 '移到下一条
On Error GoTo err30212
If frmMain.datPrimaryRS.Recordset.AbsolutePosition = adPosEOF Then
Command1(2).Enabled = False
Else
Command1(1).Enabled = True
Command1(0).Enabled = True
Command1(3).Enabled = True
frmMain.datPrimaryRS.Recordset.MoveNext
End If
err30212:
If Err.Number = 3021 Then
MsgBox "数据库没有数据", vbInformation, "移动出错..."
End If
Case 3 '移到最未条
On Error GoTo err30213
Command1(0).Enabled = True
Command1(3).Enabled = False
Command1(1).Enabled = True
frmMain.datPrimaryRS.Recordset.MoveLast
err30213:
If Err.Number = 3021 Then
MsgBox "数据库没有数据", vbInformation, "移动出错..."
End If
End Select
End Function
Private Sub Command1_Click(index As Integer)
ind = index
Call Command11(Command1, index, frmMain.datPrimaryRS, frmMain)
End Sub
红色的是模块里的...蓝色的是事件调用模块的功能
但这样不行...显示出错...类型不合
要怎么样才可以解决这个问题?
谢谢
这是我窗体的代码:
Private Sub cmdAdd_Click()
Call cmdAdd1(frmMain.datPrimaryRS, frmMain)
End Sub
Private Sub cmdClose_Click()
Unload Me
End Sub
Private Sub cmdDelete_Click()
Call cmdDelete1(cmdDelete, frmMain.datPrimaryRS, frmMain)
End Sub
Private Sub cmdRefresh_Click()
Call cmdRefresh1(frmMain.datPrimaryRS, frmMain)
End Sub
Private Sub cmdUpdate_Click()
Call cmdUpdate1(frmMain.datPrimaryRS, cmdDelete, frmMain)
End Sub
Private Sub Command1_Click(index As Integer)
Call Command11(Command1, index, frmMain.datPrimaryRS, frmMain)
End Sub
Private Sub Form_GotFocus()
frmMain.datPrimaryRS.Recordset.Open
End Sub
Private Sub Form_Load()
frmMain.datPrimaryRS.RecordSource = "select * from 部门信息"
Dim i As Integer
For i = 0 To 5
Set frm部门信息0.txtFields(i).DataSource = frmMain.datPrimaryRS
frm部门信息0.txtFields(i).DataField = Trim(frm部门信息0.lblLabels(i).Caption)
Next
End Sub
下面是我模块的代码
Public Sub cmdAdd1(datPrimaryRS As Adodc, frmMain As Form)
On Error GoTo err2147467259
frmMain.datPrimaryRS.Recordset.AddNew
err2147467259:
If Err.Number = -2147467259 Then
MsgBox "不能有重复的字段,请仔细检查后再输入", vbInformation, "输入错误"
End If
End Sub
Public Sub cmdDelete1(cmdDelete As CommandButton, datPrimaryRS As Adodc, frmMain As Form)
If frmMain.datPrimaryRS.Recordset.AbsolutePosition <> adPosEOF Then
Dim msgFlag As String
msgFlag = MsgBox("真的要删除记录吗?将不可恢复..", vbYesNo + vbInformation, "确定删除...")
If msgFlag = vbYes Then
frmMain.datPrimaryRS.Recordset.Delete
frmMain.datPrimaryRS.Recordset.MoveNext
Else
Exit Sub
End If
Else
cmdDelete.Enabled = False
End If
End Sub
Public Sub cmdRefresh1(datPrimaryRS As Adodc, frmMain As Form)
frmMain.datPrimaryRS.Refresh
End Sub
Public Sub cmdUpdate1(datPrimaryRS As Adodc, cmdDelete As CommandButton, frmMain As Form)
On Error GoTo err3021
frmMain.datPrimaryRS.Recordset.Update
cmdDelete.Enabled = True
err3021:
If Err.Number = 3021 Then
MsgBox "没有添加数据,不能保存", vbInformation, "保存出错..."
End If
End Sub
Public Sub Command11(Command1 As CommandButton, ByVal index As Integer, datPrimaryRS As Adodc, frmMain As Form)
Select Case index
Case 0 '移到第一条
On Error GoTo err3021
Command1(0).Enabled = False
Command1(3).Enabled = True
Command1(2).Enabled = True
frmMain.datPrimaryRS.Recordset.MoveFirst
err3021:
If Err.Number = 3021 Then
MsgBox "数据库没有数据", vbInformation, "移动出错..."
End If
Case 1 '移到上一条
On Error GoTo err30211
If frmMain.datPrimaryRS.Recordset.AbsolutePosition = adPosBOF Then
Command1(1).Enabled = False
Else
Command1(2).Enabled = True
Command1(0).Enabled = True
Command1(3).Enabled = True
frmMain.datPrimaryRS.Recordset.MovePrevious
End If
err30211:
If Err.Number = 3021 Then
MsgBox "数据库没有数据", vbInformation, "移动出错..."
End If
Case 2 '移到下一条
On Error GoTo err30212
If frmMain.datPrimaryRS.Recordset.AbsolutePosition = adPosEOF Then
Command1(2).Enabled = False
Else
Command1(1).Enabled = True
Command1(0).Enabled = True
Command1(3).Enabled = True
frmMain.datPrimaryRS.Recordset.MoveNext
End If
err30212:
If Err.Number = 3021 Then
MsgBox "数据库没有数据", vbInformation, "移动出错..."
End If
Case 3 '移到最未条
On Error GoTo err30213
Command1(0).Enabled = True
Command1(3).Enabled = False
Command1(1).Enabled = True
frmMain.datPrimaryRS.Recordset.MoveLast
err30213:
If Err.Number = 3021 Then
MsgBox "数据库没有数据", vbInformation, "移动出错..."
End If
End Select
End Sub