请问如何判断SQL语句值是否为空

Chris52346 2019-04-22 04:45:10
If InStr(1, Text2.Text, "%", vbTextCompare) > 0 Then
ic = "select 内码,品名,成份名,药品类别,规格,配伍禁忌 from 电子审方 where 简拼 Like '%" & Trim(Text2.Text) & "%'"
Else
ic = "select 内码,品名,成份名,药品类别,规格,配伍禁忌 from 电子审方 where 简拼 = '" & Trim(Text2.Text) & " '"
End If
Form2.Adodc1.RecordSource = ic

MsgBox "无货!"
Else
Set Form2.DataGrid1.DataSource = Form2.Adodc1
Form1.Hide
Form2.Show
End If
End Sub
End Sub

目的:IC没有结果时,提示无货,有结果时form2.show
...全文
330 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
Chris52346 2019-04-23
  • 打赏
  • 举报
回复
引用 5 楼 milaoshu1020 的回复:
可能是需要刷新一下:
Form2.Adodc1.RecordSource = ic
Form2.Adodc1.Refresh
If Form2.Adodc1.Recordset.RecordCount = 0 Then
MsgBox "无货!"
Else
Set Form2.DataGrid1.DataSource = Form2.Adodc1
Form1.Hide
Form2.Show
End If





Private Sub DataGrid1_KeyPress(KeyAscii As Integer)

Form2.DataGrid1.Col = 1
Form1.Label11.Caption = Form2.DataGrid1.Text
Form2.DataGrid1.Col = 2
Form1.Label21.Caption = Form2.DataGrid1.Text
Form2.DataGrid1.Col = 3
Form1.Label31.Caption = Form2.DataGrid1.Text
Form2.DataGrid1.Col = 4
Form1.Label41.Caption = Form2.DataGrid1.Text
Form2.DataGrid1.Col = 5
Form1.Label51.Caption = Form2.DataGrid1.Text
Form2.Hide
Form1.Show

SendKeys "{TAB}"
End Sub


非常感谢,现在遇到一个新的问题,为什么每次选择药品后,数据库里的数值会变成内码呢?
milaoshu1020 2019-04-23
  • 打赏
  • 举报
回复
可能是需要刷新一下:
Form2.Adodc1.RecordSource = ic
Form2.Adodc1.Refresh
If Form2.Adodc1.Recordset.RecordCount = 0 Then
MsgBox "无货!"
Else
Set Form2.DataGrid1.DataSource = Form2.Adodc1
Form1.Hide
Form2.Show
End If
Chris52346 2019-04-23
  • 打赏
  • 举报
回复
引用 2 楼 milaoshu1020 的回复:
错了,是recordset:

if Form2.Adodc1.RecordSet.recordcount = 0 then
MsgBox "无货!"
end if



Private Sub Command11_Click()
Dim ic
Form2.Adodc1.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=F:\李涛\慢病应用\电子审方\无密码.accdb;Jet OLEDB:Database Password=5131421arsenal"
If InStr(1, Text2.Text, "%", vbTextCompare) > 0 Then
ic = "select 内码,品名,成份名,药品类别,规格,配伍禁忌 from 电子审方 where 简拼 Like '%" & Trim(Text2.Text) & "%'"
Else
ic = "select 内码,品名,成份名,药品类别,规格,配伍禁忌 from 电子审方 where 简拼 = '" & Trim(Text2.Text) & " '"
End If
Form2.Adodc1.RecordSource = ic
If Form2.Adodc1.Recordset.RecordCount = 0 Then
MsgBox "无货!"
Else
Set Form2.DataGrid1.DataSource = Form2.Adodc1
Form1.Hide
Form2.Show
End If
End Sub



感谢回复,命令写上后还是不行,提示对象变量或with块变量未设置。您帮看看问题出在哪,谢谢
zixing 2019-04-22
  • 打赏
  • 举报
回复
嗯.楼上正解.我就来看看.
milaoshu1020 2019-04-22
  • 打赏
  • 举报
回复
错了,是recordset:

if Form2.Adodc1.RecordSet.recordcount = 0 then
MsgBox "无货!"
end if
milaoshu1020 2019-04-22
  • 打赏
  • 举报
回复
试试这样行不行:

if Form2.Adodc1.RecordSource.recordcount = 0 then
MsgBox "无货!"
end if

7,763

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧