A97:Dim dbs As Database产生错误“用户定义的类型未定义” [英] A97: Dim dbs As Database yields error "user-defined type not defined"

查看:226
本文介绍了A97:Dim dbs As Database产生错误“用户定义的类型未定义”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从A97 HELP复制了以下代码段。在编译时出错,表明存在问题

第一行(编译错误,未定义用户定义类型)。

很可能我已经遗漏了一些东西。似乎不喜欢Dim

dbs作为数据库 - 在承认

错误之后,这就是'喜欢'。你能看到这种语法有什么问题吗?


Dim dbs作为数据库,第一个作为Recordset

Dim rstEmployees作为Recordset,rstOrders作为Recordset

Dim rstProducts As Recordset,strSQL As String


''返回对当前数据库的引用。

设置dbs = CurrentDb

''创建表类型Recordset对象。

设置rstEmployees = dbs.OpenRecordset(" Employees",dbOpenTable)

''创建动态集类型Recordset对象。

设置rstOrders = dbs.OpenRecordset(" Employees",dbOpenDynaset)


''创建快照类型Recordset对象。

Set rstProducts = dbs.OpenRecordset(" Products",dbOpenSnapshot)

''每个Recordset对象的Updatable属性的打印值。

For each rst in dbs.Recordsets

Debug.Print rst.Name; "英寸; rst.Updatable

Next rst

''释放所有对象变量。

rstEmployees.Close

rstOrders.Close

rstProducts.Close

设置dbs = Nothing


如何在A97 HELP中找到示例代码(上图)...

1)点击HELP,点击目录和索引,输入dao

2)dbl-clik Recordsets在较大的字段中带垂直滚动条

3)选择第二个选项(Recordsets Collection(DAO)

4)点击示例。找到3个主题。选择最后一个名为

" Recordset Object,Recordsets Collection Example(Microsoft

Access)

I copied the following code snippet from A97 HELP. Am
getting an error at compile time suggesting there''s a problem
with the first line (compile error, user-defined type not defined).
It is likely that I''ve left something out. Doesn''t seem to like Dim
dbs as Database - that''s what''s hi-lited after acknowledging the
error. Can you see anything wrong with that syntax?

Dim dbs As Database, rst As Recordset
Dim rstEmployees As Recordset, rstOrders As Recordset
Dim rstProducts As Recordset, strSQL As String

'' Return reference to current database.
Set dbs = CurrentDb
'' Create table-type Recordset object.
Set rstEmployees = dbs.OpenRecordset("Employees", dbOpenTable)
'' Create dynaset-type Recordset object.
Set rstOrders = dbs.OpenRecordset("Employees", dbOpenDynaset)

'' Create snapshot-type Recordset object.
Set rstProducts = dbs.OpenRecordset("Products", dbOpenSnapshot)
'' Print value of Updatable property for each Recordset object.
For Each rst In dbs.Recordsets
Debug.Print rst.Name; " "; rst.Updatable
Next rst
'' Free all object variables.
rstEmployees.Close
rstOrders.Close
rstProducts.Close
Set dbs = Nothing

How to find the example code (above) in A97 HELP...
1) Click HELP, click Contents and Index, type "dao"
2) dbl-clik Recordsets In the larger field w/ vertical scroll bar
3) Pick the 2nd choice (Recordsets Collection (DAO)
4) Click Example. 3 topics are found. Choos the last one entitled
"Recordset Object, Recordsets Collection Example (Microsoft
Access)

推荐答案

MLH写道:
MLH wrote:
我从A97 HELP复制了以下代码片段。在编译时遇到错误表明第一行存在问题(编译错误,用户定义类型未定义)。
很可能我已离开出来的东西。似乎并不喜欢Dim
dbs作为数据库 - 在确认
错误之后,这就是什么了。你能看到这种语法有什么问题吗?

Dim dbs作为数据库,rst作为Recordset
Dim rstEmployees作为Recordset,rstOrders作为Recordset
Dim rstProducts作为Recordset,strSQL As String
I copied the following code snippet from A97 HELP. Am
getting an error at compile time suggesting there''s a problem
with the first line (compile error, user-defined type not defined).
It is likely that I''ve left something out. Doesn''t seem to like Dim
dbs as Database - that''s what''s hi-lited after acknowledging the
error. Can you see anything wrong with that syntax?

Dim dbs As Database, rst As Recordset
Dim rstEmployees As Recordset, rstOrders As Recordset
Dim rstProducts As Recordset, strSQL As String




这很奇怪。以上是否粘贴了您的代码?我确实提到了你提到的

类错误,但只有当我误解了这样的事情时

例子里面有整数的错误。错误拼写:dim int1 as intger。

-

Tim http://www.ucs.mun.ca/~tmarshal/

^ o<

/#)打嗝,打嗝,打嗝? - Quaker Jake

/ ^^Whatcha doin? - 同上TIM-MAY !! - 我



That''s weird. Is the above pasted from your code? I get exactly the
kind of error you mention, but only when I mispell something like this
example where "Integer" is misspelled: "dim int1 as intger".
--
Tim http://www.ucs.mun.ca/~tmarshal/
^o<
/#) "Burp-beep, burp-beep, burp-beep?" - Quaker Jake
/^^ "Whatcha doin?" - Ditto "TIM-MAY!!" - Me


< snip>
<snip>

这很奇怪。以上是否粘贴了您的代码?我明白了你提到的那种错误,但只有当我误解了这样的事情时
例如,整数错误拼写:dim int1 as intger。

That''s weird. Is the above pasted from your code? I get exactly the
kind of error you mention, but only when I mispell something like this
example where "Integer" is misspelled: "dim int1 as intger".




是的。我直接从A97 HELP复制了这个例子,将它粘贴在命令按钮后面的




如何在A97帮助中找到示例代码...

1)单击帮助,单击目录和索引,键入dao

2)dbl-clik Recordsets在较大的字段中带垂直滚动条

3)选择第二个选项(Recordsets Collection(DAO)

4)点击示例。找到3个主题。选择最后一个名为

" Recordset Object,Recordsets Collection Example(Microsoft

Access)



Yes. And I copied the example straight from A97 HELP, pasting it
behind a command button.

How to find the example code in A97 HELP...
1) Click HELP, click Contents and Index, type "dao"
2) dbl-clik Recordsets In the larger field w/ vertical scroll bar
3) Pick the 2nd choice (Recordsets Collection (DAO)
4) Click Example. 3 topics are found. Choos the last one entitled
"Recordset Object, Recordsets Collection Example (Microsoft
Access)


Tim Marshall写道:
Tim Marshall wrote:
标准的默认库,换句话说......你的参考文献中还有其他什么吗?我想知道是否有任何遗漏,或者是否有其他可能干扰的东西。你有ADO图书馆的参考资料吗?
The standard default libraries, in other words... Do you have anything
else in your references? I wonder if anyting is missing or if there''s
something else there that might be interfering. Do you have a reference
to an ADO library?




查看你的其他帖子,如果你的原帖有问题

起源于你描述的问题,我怀疑,这可能是

问题。


但是,如果你改变你的代码来指定记录集变量

是DAO,而不是ADO,即


Dim dbs作为DAO.Database,rst作为DAO.Recordset

Dim rstEmployees作为DAO.Recordset,rstOrders作为DAO.Recordset

Dim rstProducts作为DAO.Recordset,strSQL作为字符串


(我也投入了数据库变量) ,好的措施)


这有望让A97区分DAO和ADO。


如果以上不起作用,我会集中精力解决你在另一个线程中提出的另一个问题,我确定这个问题在

这个线程会消失。


不幸的是,我不能在另一个问题上大肆宣传 - 我总是在我的开发工作中倾向于远离OCXs,因为我们在第一次看到

时已经在cdma中对它们进行了各种警告90年代,在A2000之前发布了
。这并不是说它们不是一个好主意 - 有成功使用它们的开发人员,只是我是一个管理者,
$ b $呃,我组织的经理,并选择不与他们玩。 8)


希望这有一些帮助...

-

Tim http://www.ucs.mun.ca/~tmarshal/

^ o<

/#)Burp-beep,burp-beep,burp-beep? - Quaker Jake

/ ^^Whatcha doin? - 同上TIM-MAY !! - 我



Looking at your other post, if the problem with your original post here
originated AFTER the problem you describe, I suspect, that might be the
problem.

However, if you alter your code to specify that the recordset variables
are DAO, not ADO, ie,

Dim dbs As DAO.Database, rst As DAO.Recordset
Dim rstEmployees As DAO.Recordset, rstOrders As DAO.Recordset
Dim rstProducts As DAO.Recordset, strSQL As String

(I threw in the database variable as well, for good measure)

This will hopefully allow A97 to distinguish between DAO and ADO.

If the above does not work, I would concentrate on resolving the other
issue you bring up in your other thread and I''m certain the problem in
this thread will go away.

Unfortunately, I can''t offer much in the other issue - I''ve always
tended to stay away from OCXs in my development work since first seeing
various cautions about them in cdma in the late 90s, before A2000 was
released. That''s not to say they are not a good idea - there are loads
of developers who successfully use them, it''s just that I am a mangler,
er, a manager in my organization and chose not to play around with them. 8)

Hope this was of some help...
--
Tim http://www.ucs.mun.ca/~tmarshal/
^o<
/#) "Burp-beep, burp-beep, burp-beep?" - Quaker Jake
/^^ "Whatcha doin?" - Ditto "TIM-MAY!!" - Me


这篇关于A97:Dim dbs As Database产生错误“用户定义的类型未定义”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆