确定列表框是否具有值 [英] Determine if listbox has values

查看:71
本文介绍了确定列表框是否具有值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请帮助,


我们有一个基于查询的表单,其中包含一个列表框。列表框中的内容基于查询结果。


打开表单时,用户从列表框中选择一个项目, ,

使用AfterUpdate和Visible属性,子窗体显示相对于所选项目的

信息。


它完美地工作。


但我们希望创建一个简单的MsgBox,如果未填充列表框,则说无记录

,这样当用户点击命令

打开表格,他/她得到的是MsgBox而不是表格。


这可能吗?

感谢您提供任何帮助或建议的链接。

Help please,

We have a form, based on a query, that contains a listbox. The contents of
the listbox are based on the results of the query.

When the form is opened, the user selects an item from the listbox, and,
using the AfterUpdate and Visible properties, a subform appears with
information relative to the selected item.

It works perfectly.

But we wish to create a simple MsgBox the says something like "No Records"
if the listbox is not populated, so that when the user clicks the command to
open the form, he/she gets the MsgBox and not the form.

Is this possible?

Thank you for any help or suggested links.

推荐答案

IF listbox.rowsource =""然后

msgbox(没有记录)

否则

~这里的代码

结束IF

IF listbox.rowsource = "" Then
msgbox("No Records")
Else
~ code here
End IF


" Beacher" <是***** @ gmail.com>在消息中写道

news:11 ********************** @ o13g2000cwo.googlegr oups.com ...
"Beacher" <be*****@gmail.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
IF listbox.rowsource =""然后
msgbox(没有记录)
其他
〜这里的代码
结束IF
IF listbox.rowsource = "" Then
msgbox("No Records")
Else
~ code here
End IF




嗯 - 如果没有什么可以改变列表框的行源,那么也许

你可能会更好用的东西比如


Dim strSQL As String

Dim db作为数据库

Dim rst作为记录集


strSQL = List0.RowSource


设置db = CurrentDb

设置rst = db.OpenRecordset(strSQL,dbOpenSnapshot)


rst

如果.EOF和.BOF那么

''没有什么可以显示的 - 出去

MsgBox没有要选择的记录,vb信息

''DoCmd.Close acForm ,Me.Name

否则

''随着你的表格打开,做任何好事

结束如果

。关闭

结束


Set rst = Nothing

设置db = Nothing


或者,如果您可以预测列表框所基于的SQL或查询n

甚至不打扰列表框引用而只是使用它。


hth




Well - if there''s nothing changing the rowsource of the listbox then perhaps
you might be better off with something like

Dim strSQL As String
Dim db As Database
Dim rst As Recordset

strSQL = List0.RowSource

Set db = CurrentDb
Set rst = db.OpenRecordset(strSQL, dbOpenSnapshot)

With rst
If .EOF And .BOF Then
''There is nothing to show - get out
MsgBox "No records to select", vbInformation
''DoCmd.Close acForm, Me.Name
Else
''Do whatever happns as your form opens
End If
.Close
End With

Set rst = Nothing
Set db = Nothing

Or if you can predict the SQL or query that the listbox is based upon then
don''t even bother with the listbox reference and just use that instead.

hth



LeighP写道:
如果.EOF和.BOF那么
If .EOF And .BOF Then




注意:我''我最近有过.BOF和.EOF都是假的情况

但是没有记录,我现在用.RecordCount检查这个。


-

[OO = 00 = OO]



Beware: I''ve recently had instances where both .BOF and .EOF were false
yet there were no records, I use .RecordCount to check this now.

--
[OO=00=OO]


这篇关于确定列表框是否具有值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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