设为首页收藏本站Access中国

Office中国论坛/Access中国论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

返回列表 发新帖
查看: 1660|回复: 2
打印 上一主题 下一主题

[查询] 查询条件引起的问题 附代码

[复制链接]
跳转到指定楼层
1#
发表于 2008-5-30 09:26:11 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
Private Sub cmdReport_Click()
Dim X As Form
Dim sql_RS As String
DoCmd.Hourglass True
Application.Echo False
DoCmd.SetWarnings False
Me.Requery
If Not IsNull(Val(Me!testbatchNo)) Then
Set X = Forms![frmH-alpha_Test_Data].Form
DoCmd.OpenForm "frmH-alpha_Test_Data", , , , acFormEdit
'''''''''''''''''''''''''''''''''在程序执行到下面的sql语句时就出现you canceled the previous operation的错误,发现是where条件设置的问题
''''''''''''''''''''''''''''''''''其中testbatchNo 为TempImport表的栏位Val(Me!cboSample.Column(2))为窗体的值,执行是有值的

X.RecordSource = "SELECT TempImport.[lamp-No], TempImport.testbatchNo, tblHalphatstedescription.serialNo " _
            & " FROM tblHalphatstedescription INNER JOIN TempImport ON tblHalphatstedescription.serialNo = TempImport.testbatchNo" _
           & " where testbatchNo = '" & Val(Me!cboSample.Column(2)) "' ORDER BY TempImport.[lamp-No], TempImport.testbatchNo, TempImport.Meas_pos;"

else
MsgBox "Please select items you want to print out !", vbOKOnly, "Select prompt!"
End If
Exit_cmdReport_Click:
    DoCmd.Hourglass False
    Application.Echo True
    DoCmd.SetWarnings True
    Exit Sub
End Sub
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享分享 分享淘帖 订阅订阅

点击这里给我发消息

2#
发表于 2008-5-30 10:15:11 | 只看该作者
testbatchNo是什么类型的值? 是文本型号就加单引号,否则不用加的.

点击这里给我发消息

3#
发表于 2008-5-30 10:42:11 | 只看该作者
原帖由 beaccesssuper 于 2008-5-30 09:26 发表
Private Sub cmdReport_Click()
Dim X As Form
Dim sql_RS As String
DoCmd.Hourglass True
Application.Echo False
DoCmd.SetWarnings False
Me.Requery
If Not IsNull(Val(Me!testbatchNo)) Then
Set X  ...


Private Sub cmdReport_Click()
Dim X As Form
Dim sql_RS As String
DoCmd.Hourglass True
Application.Echo False
DoCmd.SetWarnings False
Me.Requery
If Not IsNull(Val(Me!testbatchNo)) Then
Set X = Forms![frmH-alpha_Test_Data].Form
DoCmd.OpenForm "frmH-alpha_Test_Data", , , , acFormEdit

Dim SomeValue
SomeValue = Val(Me!cboSample.Column(2))

X.RecordSource = "SELECT TempImport.[lamp-No], TempImport.testbatchNo, tblHalphatstedescription.serialNo " _
            & " FROM tblHalphatstedescription INNER JOIN TempImport ON tblHalphatstedescription.serialNo = TempImport.testbatchNo" _
           & " where testbatchNo = '" & SomeValue & "' ORDER BY TempImport.[lamp-No], TempImport.testbatchNo, TempImport.Meas_pos;"

else
MsgBox "Please select items you want to print out !", vbOKOnly, "Select prompt!"
End If
Exit_cmdReport_Click:
    DoCmd.Hourglass False
    Application.Echo True
    DoCmd.SetWarnings True
    Exit Sub
End Sub
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|站长邮箱|小黑屋|手机版|Office中国/Access中国 ( 粤ICP备10043721号-1 )  

GMT+8, 2024-11-26 01:41 , Processed in 0.106276 second(s), 26 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表