求高人帮忙 VB的问题

来源:百度知道 编辑:UC知道 时间:2024/06/18 04:50:33
Public Function ExecuteSQL(ByVal SQL As String, MsgString As String) As ADODB.Recordset

End Function

Private Sub Command1_Click()
Dim mrc As ADODB.Recordset
Dim txtsql As String
Dim msgtext As String

If Trim(Text1.Text) = "" Then
MsgBox "请输入学号", vbOKOnly, "警告"
Text1.SetFocus
Exit Sub
End If

If Text2.Text = "" Then
MsgBox "请输入姓名", vbOKOnly, "警告"
Text2.SetFocus
Exit Sub
End If

If Text3.Text = "" Then
MsgBox "请输入出生日期", vbOKOnly, "警告"
Text3.SetFocus
Exit Sub
End If

If Not IsDate(Text3.Text) Then
MsgBox "日期的正确格式应为(YYYY-MM-DD)", vbOKOnly, "警告"
Text3.SetFocus
Exit Sub
End If

If Text4.Text = "" Then
MsgBox "请输入班级"

‘帮你改了看可以吗?主要是帮你修改 Function 写法和呼叫Function 的写法。

Dim cn As New ADODB.Connection
Dim mrc As New ADODB.Recordset

Public Function ExecuteSQL(ByVal SQL As String, MsgString As String) As ADODB.Recordset
cn.ConnectionString = "provider=Microsoft.jet.OLEDB.4.0;Persist security info= False; Data source=" & App.Path & "\数据库名称.mdb"
cn.Open

mrc.CursorLocation = adUseClient
mrc.Open Trim$(SQL), cn, adOpenKeyset, adLockPessimistic
Set ExecuteSQL = mrc
End Function

Private Sub Command1_Click()
Dim mrc As ADODB.Recordset
Dim txtsql As String
Dim msgtext As String

If Trim(Text1.Text) = "" Then
MsgBox "请输入学号", vbOKOnly, "警告"
Text1.SetFocus
Exit Sub
End If

If Text2.Text = "" Then
MsgBox "请输入姓名", vbOKOnly, "警告"
Text2.SetFocus
Exit Sub