1、登陆按钮的代码如下:
Private Sub cmdOK_Click()
    Dim mrc As ADODB.Recordset
    Dim strmsg As String
    txtSQL = "select uid from userinfo where UID='" & Trim(txtUserName.Text) & "'"
    Set mrc = ExecuteSQL(txtSQL, strmsg)
    If mrc.EOF = True Then
        MsgBox " 用户名错误!", vbExclamation + vbOKOnly, "警告"
        txtUserName.SetFocus
        txtUserName.SelStart = 0
        txtUserName.SelLength = Len(txtUserName.Text)
        Exit Sub
    End If
    UserName = mrc.Fields(0)
    txtSQL = "select UID from userinfo where PWD='" & Trim(txtPassword.Text) & "'"
    Set mrc = ExecuteSQL(txtSQL, strmsg)
    If mrc.EOF = True Then 执行后指示此处出错,出错信息如标题所示
        MsgBox " 密码错误!", vbExclamation + vbOKOnly, "警告"
        txtPassword.SetFocus
        txtPassword.SelStart = 0
        txtPassword.SelLength = Len(txtPassword.Text)
        Exit Sub
    End If
    OK = True
    frmMain.Show
    Unload Me
End Sub2、模块代码如下
Public frmMain As frmMain
Public gintMode As Integer
Public flagEdit As Boolean
Public UserName As String
Sub Main()
   frmLogin.Show
End Sub
Public Function ExecuteSQL(ByVal SQL _
   As String, MsgString As String) _
   As ADODB.Recordset
'executes SQL and returns Recordset
   Dim ConnectString As String
   ConnectString = "Provider=SQLOLEDB.1;" & _
                   "Persist Security Info=False;" & _
                   "UID=vb;PWD=sa;" & _
                   "Initial Catalog=PersonMIS.mdf;" & _
                   "Data Source=(local)"
   Dim cnn As ADODB.Connection
   Dim rst As ADODB.Recordset
   Dim sTokens() As String
   
   On Error GoTo ExecuteSQL_Error
   
   sTokens = Split(SQL)
   Set cnn = New ADODB.Connection
   cnn.Open ConnectString
   If InStr("INSERT,DELETE,UPDATE", _
      UCase$(sTokens(0))) Then
      cnn.Execute SQL
      MsgString = sTokens(0) & _
         " query successful"
   Else
      Set rst = New ADODB.Recordset
      rst.Open Trim$(SQL), cnn, _
         adOpenKeyset, _
         adLockOptimistic
      'rst.MoveLast     'get RecordCount
      Set ExecuteSQL = rst
      MsgString = "查询到" & rst.RecordCount & _
         " 条记录 "
   End If
ExecuteSQL_Exit:
   Set rst = Nothing
   Set cnn = Nothing
   Exit Function
   
ExecuteSQL_Error:
   MsgString = "查询错误: " & _
      Err.Description
   Resume ExecuteSQL_Exit
End Function
'将enter换成tab
Public Sub EnterToTab(Keyasc As Integer)
    If Keyasc = 13 Then
        SendKeys "{TAB}"
    End If
End Sub
补充:我已经在sql server 2005中新建了一个vb的用户且密码是sa,并将PersonMIS数据库加入其中,求大神解决,感激涕霖