下面的就是公共模块里的程序:
Option Explicit
Public gConnStr As String
Public Sub ChangeFormPos(frmMain As MDIForm, frm As Form)
Dim Top As Integer
Top = (frmMain.ScaleHeight - frm.Height) / 2 - 600
If Top > 0 Then
frm.Top = Top
Else
frm.Top = 0
End If
frm.Left = (frmMain.ScaleWidth - frm.Width) / 2
End Sub
Public Sub Main()
gConnStr = "provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;用户编号=sa;用户密码=sa;Initial Catalog=人事工资;Data Source=A97A598C4CCB4B5"
F系统登录.Show
End Sub
Public Function ExeSQL(ByVal sql As String) As ADODB.Recordset
On Error GoTo ErrHandler
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim strArray() As String
Set cn = New ADODB.Connection
Set rs = New ADODB.Recordset
strArray = Split(sql)
cn.Open gConnStr
If StrComp(UCase$(strArray(0)), "select", vbTextCompare) = 0 Then
rs.Open Trim$(sql), cn, adOpenForwardOnly, adLockBatchOptimistic
Set ExeSQL = rs
Else
cn.Execute sql
End If
ExeSQL_Exit:
Set rs = Nothing
Set cn = Nothing
ErrHandler:
'显示错误信息
MsgBox "错误号:" & Err.Number & "错误信息:" & Err.Description, vbExclamation
Resume ExeSQL_Exit
End Function
[[it] 本帖最后由 QWJ2008 于 2008-4-6 09:54 编辑 [/it]]