为什么这个SQL记录集不能在Outlook VBA中打开? ! ? [英] Why will this SQL recordset not open in outlook VBA ? ! ?

查看:92
本文介绍了为什么这个SQL记录集不能在Outlook VBA中打开? ! ?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的程序的其他区域使用类似的代码,我的数据库似乎工作正常,SQL行在Management Studio中正常工作,但每次我到达这一点,程序退出例程,它只是一旦它到达.Open行就跳到End Sub ...如果数据库出现问题,当我检查状态(返回0)时我肯定会收到错误吗?!?





I use similar code to this in other areas of my program, my Database seems to be working OK, the SQL line works OK in Management Studio, but every time I get to this point, the program exits the routine, it just skips to the End Sub as soon as it hits the .Open line ... If there is a problem with the Database, surely I should get an error when I check the State (which returns 0) ?!?


Sub LoopDatabaseLeague()

On Error GoTo LoopDatabaseLeagueError

SQLstr = "SELECT Name, LeagueType_ID From League Where League.[LeagueType_ID] = '2';"

myEmailFolder = ""

Set KA_RS_League = New ADODB.Recordset

If KA_RS_League.State = adStateOpen Then KA_RS_League.Close <<< State = 0

KA_RS_League.Open SQLstr, KA_DB, adOpenDynamic, adLockOptimistic <<< This line skips to the end

Do Until KA_RS_League.EOF
    KA_Which_Newsletter.ComboBox1.AddItem (KA_RS_League![Name])
    If FindString(mySubject, KA_RS_League![Name]) Then
        myEmailFolder = KA_RS_League![Name]
    End If
    KA_RS_League.MoveNext
Loop
    
KA_RS_League.Close

LoopDatabaseLeagueError:

End Sub





我的尝试:



不同的代码,搜索互联网,查找错误代码



What I have tried:

Different code, searched internet, looked for error codes

推荐答案

我丢失了我的连接到数据库的某个地方,不知道为什么&am磷;不知道为什么程序不能只告诉我!!!



无论如何现在已经解决了,谢谢你的帮助......
I was losing my Connection to the database somewhere along the line, no idea why & no idea why the program cannot just tell me that !!!

Resolved now anyway, thanks for your help ...


这篇关于为什么这个SQL记录集不能在Outlook VBA中打开? ! ?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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