Compile Error: variable not defined (VB6)
Compile Error: variable not defined (VB6)
您好,我正在尝试 link 从 Access 到 VB6 的数据库。然后我尝试使用 ListView 以 table 形式显示数据库中记录的内容。我已经检查了 References 和 Components needed 但我总是收到同样的错误。它说编译错误:未为此代码的 header 定义变量:
Sub dbconnection()
connect.Open "Provider=Microsoft.jet.OLEDB.4.0;"
Data Source = "C:\Users\Admin\Documents\werk\LAST SEM!!!!!!!!\CSC301\Foot-it!\ftsdb.mdb"
End Sub
我已经在代码的顶部声明了 Option Explicit,如下所示:
Option Explicit
Dim connect As New ADODB.Connection
Dim rs As New ADODB.Recordset
我对此很陌生,老实说,我只是在 Youtube 上查了一下。任何类型的帮助将不胜感激。提前致谢。
PS:如果您需要更多详细信息,请发表评论,我会进行编辑以供您澄清。
Data Source = "C:\Users\Admin\Documents\werk\LAST SEM!!!!!!!!\CSC301\Foot-it!\ftsdb.mdb"
"Data"曾经是BASIC早期版本的保留字。
我与 SQL 的合作不多,但我猜你想做的更像是:
connect.DataSource = "C:\Users\Admin\Documents\werk\LAST SEM!!!!!!!!\CSC301\Foot-it!\ftsdb.mdb"
或
rs.DataSource = "C:\Users\Admin\Documents\werk\LAST SEM!!!!!!!!\CSC301\Foot-it!\ftsdb.mdb"
这里的其他具有更多 ADO 经验的人可能能够确认哪个是正确的。
EDIT: Please refer to Luke G.'s answer, as it is the correct answer.
Mine, though marked as accepted, I realize is incorrect.
您的问题是因为 'Data Source' 位需要成为上一行的一部分。您应该通过在 open 语句中指定连接驱动程序和参数来打开连接。
试试这个:
connect.Open "Provider=Microsoft.jet.OLEDB.4.0;Data Source=C:\Users\Admin\Documents\werk\LAST SEM!!!!!!!!\CSC301\Foot-it!\ftsdb.mdb"
您好,我正在尝试 link 从 Access 到 VB6 的数据库。然后我尝试使用 ListView 以 table 形式显示数据库中记录的内容。我已经检查了 References 和 Components needed 但我总是收到同样的错误。它说编译错误:未为此代码的 header 定义变量:
Sub dbconnection()
connect.Open "Provider=Microsoft.jet.OLEDB.4.0;"
Data Source = "C:\Users\Admin\Documents\werk\LAST SEM!!!!!!!!\CSC301\Foot-it!\ftsdb.mdb"
End Sub
我已经在代码的顶部声明了 Option Explicit,如下所示:
Option Explicit
Dim connect As New ADODB.Connection
Dim rs As New ADODB.Recordset
我对此很陌生,老实说,我只是在 Youtube 上查了一下。任何类型的帮助将不胜感激。提前致谢。
PS:如果您需要更多详细信息,请发表评论,我会进行编辑以供您澄清。
Data Source = "C:\Users\Admin\Documents\werk\LAST SEM!!!!!!!!\CSC301\Foot-it!\ftsdb.mdb"
"Data"曾经是BASIC早期版本的保留字。
我与 SQL 的合作不多,但我猜你想做的更像是:
connect.DataSource = "C:\Users\Admin\Documents\werk\LAST SEM!!!!!!!!\CSC301\Foot-it!\ftsdb.mdb"
或
rs.DataSource = "C:\Users\Admin\Documents\werk\LAST SEM!!!!!!!!\CSC301\Foot-it!\ftsdb.mdb"
这里的其他具有更多 ADO 经验的人可能能够确认哪个是正确的。
EDIT: Please refer to Luke G.'s answer, as it is the correct answer. Mine, though marked as accepted, I realize is incorrect.
您的问题是因为 'Data Source' 位需要成为上一行的一部分。您应该通过在 open 语句中指定连接驱动程序和参数来打开连接。
试试这个:
connect.Open "Provider=Microsoft.jet.OLEDB.4.0;Data Source=C:\Users\Admin\Documents\werk\LAST SEM!!!!!!!!\CSC301\Foot-it!\ftsdb.mdb"