Access 2007记录集问题 [英] Access 2007 Recordset problem

查看:88
本文介绍了Access 2007记录集问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将Access 2003(运行良好)迁移到Access2007.用VBA编写的代码会引起一些问题.就像我有一个主要形式和2个子形式.在动态查询设置的主表单记录源集中,但是当我尝试设置子表单的Recordset时,它基于主表单数据,然后访问2007 crash&关闭自己.您能否帮助任何人找出为什么在Access 2007中会发生这种情况.

I am trying to migrate Access 2003 (running fine) to Access 2007. The code written in VBA creates some issues. Like I have one main form and 2 subform. In main form recordsource set set by a Dynamic query but based on main form data when I am trying to set the Recordset of subform then access 2007 crash & close itself. Could you please help any one to find out why this occur in access 2007.

Public Sub LoadRecord(strRecId As String)

On Error Resume Next

Dim ctl As Access.Control
Dim strsql As String
Dim strID As String
Dim rs As ADODB.Recordset

    strsql = "SELECT * from vwContractsMainForm WHERE ID = '" & strRecId & "'"

    Call OLEDBConnect 
    Set rs = New ADODB.Recordset
    With rs
        Set .ActiveConnection = cnn
        .Source = strsql
        .CacheSize = 1
        .LockType = adLockOptimistic
        .CursorType = adOpenKeyset
        .CursorLocation = adUseServer
        .Open
    End With

    'Set the first sub form's Recordset property to the ADO recordset 
    Set Me.Recordset = rs   '-------- this part creates the problem.
    Me.UniqueTable = "tbl_contracts"
    Set rs = Nothing
    Set cnn = Nothing

推荐答案

我会很生气.我这个月学到了一些有关Access的新知识.我从未意识到您可以更改这种形式的记录集.

I'll be darned. I learned something new about Access this month. I never realized you could change the recordset of a form like that.

我从来没有使用过错误恢复下一步,因为您可能会在崩溃的行之前的行中隐藏错误消息.

I've never use an On Error Resume Next as you might be, likely are, hiding an error message on a line previous to the line which crashes.

愚蠢的问题. strRecId是查询中的数字字段还是字符串字段?报价有效吗?

Stupid question. Is strRecId a numeric or string field in the query? Are the quotes valid?

strRecoID和cnn在您的代码中未变暗.我看到strID变暗了,所以您可能打算使用该字段.请添加Option Explicit作为模块的第一行或第二行.然后进入每个模块并添加这些行.然后进行编译,看看还有多少其他错误发生.

strRecoID and cnn are not Dimmed in your code. I see strID is dimmed so that's likely the field you meant to use. Please add Option Explicit as the top or second line of your module. Then go into every module and add those lines. Then do a compile and see how many other errors happen.

还进入VBA编辑器,然后进入工具" >>选项" >>,并确保选中了要求变量声明"框.

Also go into the VBA Editor then Tools >> Options >> and ensure the Require Variable Declaration box is checked.

您和所有潜伏者也是如此.请将崩溃信息发送给Microsoft.当然,尽管他们不喜欢获取崩溃信息,但他们确实将崩溃视为服务包的当务之急.

Also to you and all lurkers. Please send in the crash information to Microsoft. While they, of course, don't like getting crash information, they do treat crashes as a very high priority when it comes to Service Packs.

这篇关于Access 2007记录集问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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