解决文章中问题的具体步骤?
公用模块:Model.bas
public username as string
Public Function ExecuteSQL(ByVal SQL As String,_
MsgString As String) As ADODB.Recordset
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
Public function connectstring() as string
connectstring=”fileDSN=studentinfo.dsn;UID=sa;_PWD=”
End function
Public function testtxt(txt as string) as Boolean
If trim(txt)=”” then
Testtxt=false
Else
Testtxt=true
End if
End function
Sub main()
Dim flogin as new frmlogin
Flogin.show vbmodal
If not flogin.ok then
Login failed so exit app
End
End if
Unload flogin
Set fmainform=new frmmain
Fmainform.show
End sub
有一登录窗口
登录窗口中各个控件的属性设置如下:
控件 属性 属性取值
Frmlogin(form) Name Frmlogin
Caption 登录
Startuppositon Centerscreen
windowstate Nomal
Txtusername name Txtusername
txtpassword name Txtpassword
name *
cmdok name Cmdok
caption 确定
cmdcancel name Cmdcancel
caption 取消
Label1 Caption 学生管理信息系统
Label2 Caption 用户名
Label3 Caption 用户密码
Option explicit
Public ok as Boolean
Dim micount as integer
Private sub form_load()
Ok=false
Micount=0
End sub
Private sub cmdok_click()
Dim txtSQL as string
Dim mrc as ADODB.recordset
Dim msgtext as string
Username=””
If trim(txtusername.txt=””) then
Msgbox “ !”,vbokonly+vbexclamation
Txtusernae.setfocus
Else
TxtSQL=”select * from user_info where user_ID=”” & txtusername.text & “”
Set mrc=executeSQL(txtSQL,msgtext)
If mrc.eof=true then
Msgbox “ !”,vbokonly+vbexclamation
Txtusername.setfocus
Else
If trim(mrc.fields(1))=trim(txtpassword.text) then
Ok=true
Mrc.close
Me.hide
Username=trim(txtusername.text)
Else
Msgbox “ !”,vbokonly+vbexclamation
Txtpassword.setfocus
Txtpassword.text=””
End if
End if
End if
Exit sub
End sub
Private sub cmdcancel_click()
Ok=false
Me.hide
End sub
数据库名为DB.mdb 数据表user_info
运行上述过程后,在if mrc.eof=true then语句 提示”对象变量或WITH块变量未设置”。请问怎么解决?请告诉具体步骤!