求助:vb 运行发生实时错误'91'
在我的标准模块中有如下数据库连接代码
Public Sub DBopen()
On Error GoTo DBExt_Error
ConnStr = "Provider=SQLOLEDB.1;User ID= " & UserName & "Password= " & LoginPwd & "Persist Security Info=False;Initial Catalog=stu;Data Source= " & DataBaseIp
Set Conn = New ADODB.Connection
Conn.Open ConnStr
Exit Sub
DBExt_Error:
msgbox "连接数据库出错,请重新配置 "
Dim fDBC As New frm_DataBaseConnection
Set fDBC = New frm_DataBaseConnection
fDBC.Show
End Sub
程序运行到(fDBC.Show)跳出窗口的同时,提示了如下错误:
运行时错误 '91 '
未设置对象变量或With block变量
frm_DataBaseConnection是一个FORM配置登陆信息窗口,我该怎么解决?
[解决办法]
申明模块是如dim test as new 工程名.模块名
试试.
[解决办法]
91y要么没有引用 ado要么 连接字符串或者 sql错误 打断点 测试下
[解决办法]
改為
Public Sub DBopen()
On Error GoTo DBExt_Error
ConnStr = "Provider=SQLOLEDB.1;User ID= " & UserName & "Password= " & LoginPwd & "Persist Security Info=False;Initial Catalog=stu;Data Source= " & DataBaseIp
Set Conn = New ADODB.Connection
Conn.Open ConnStr
Dim fDBC As New frm_DataBaseConnection
Set fDBC = New frm_DataBaseConnection
fDBC.Show
Exit Sub
DBExt_Error:
msgbox "连接数据库出错,请重新配置 "
End Sub
怎麼能把Dim fDBC As New frm_DataBaseConnection
Set fDBC = New frm_DataBaseConnection
fDBC.Show
寫在DBExt_Error裡呢
程式無論在什麼時候一定是順序執行的
[解决办法]
fDBC.Show
你在 frm_DataBaseConnection form_load里面写了什么。把断点放在那里看看
[解决办法]
用msgbox把连接语句输出,先查看连接语句。然后使用odbc来判断看这句话是否有误。会告诉您哪里错误了。