计算记录以显示错误消息。 [英] Counting records to diplay an error message.

查看:58
本文介绍了计算记录以显示错误消息。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


我的数据库用户,工作和预订中有三个表。它是一个工作预订系统,因此用户登录并对工作进行预订。我试图按一下按钮来显示错误信息,如果他们试图预订但已经有15个或更多。


下面是我到目前为止的代码任何人都可以帮助我让它工作或指向正确的方向。

Hi all,

There are three tables in my database user, job and booking. It?s a job booking system so users login and make a booking against a job. I?m trying to get a button to display an error message if they try to make a booking but already have made 15 or more.

Below is the code I?ve got so far can anyone help me to get it working or point me in the right direction.

展开 | 选择 | Wrap | 行号

推荐答案

你不能使用RunSQL,因为这是用于动作查询,而是使用记录集或域函数


例如域函数 - DCOUNT


DCOUNT(*,tblBooking,userid =用户名和jobStatus = open")


以上示例采用您的过滤器,我假设您相应地修改它。它返回预订的数量


记录集示例是这样的


Dim用户名字符串

Dim strSQL As String

Dim rs as dao.recordset

Dim lCount as


strSQL = SELECT Count(*)AS numberOfBookings FROM tblBooking WHERE userId = username AND jobStatus = open"

set rs = currentdb.openrecordset(strSQL)

lCount = 0

如果rs.eof = false那么

rs.movelast

lCount = rs.RecordCount

endif

rs.close

set rs = nothing


如果lCount< = 15那么

MsgBox你有15个或更多的公开预订,请在继续之前关闭预订
u cannot use RunSQL as this is for action queries, instead use a recordset or a domain function

eg domain function - DCOUNT

DCOUNT("*","tblBooking","userid = username AND jobStatus = open")

example above takes your filter, I assume u modify it accordingly. It returns the number of bookings

the recordset example is like this


Dim username As String
Dim strSQL As String
Dim rs as dao.recordset
Dim lCount as long


strSQL = "SELECT Count(*) AS numberOfBookings FROM tblBooking WHERE userId = username AND jobStatus = open "
set rs=currentdb.openrecordset (strSQL)
lCount = 0
if rs.eof = false then
rs.movelast
lCount = rs.RecordCount
endif
rs.close
set rs=nothing


If lCount <= 15 Then
MsgBox "You have 15 or more open bookings, please close bookings before proceeding"



u不能使用RunSQL,因为这是用于操作查询,而是使用记录集或域功能


例如域名功能 - DCOUNT


DC OUNT(*,tblBooking,userid = username AND jobStatus = open)


以上示例采用您的过滤器,我假设您相应地修改它。它返回预订的数量


记录集示例是这样的


Dim用户名字符串

Dim strSQL As String

Dim rs as dao.recordset

Dim lCount as


strSQL = SELECT Count(*)AS numberOfBookings FROM tblBooking WHERE userId = username AND jobStatus = open"

set rs = currentdb.openrecordset(strSQL)

lCount = 0

如果rs.eof = false那么

rs.movelast

lCount = rs.RecordCount

endif

rs.close

set rs = nothing


如果lCount< = 15那么

MsgBox您有15个或更多的公开预订,请在继续之前关闭预订
u cannot use RunSQL as this is for action queries, instead use a recordset or a domain function

eg domain function - DCOUNT

DCOUNT("*","tblBooking","userid = username AND jobStatus = open")

example above takes your filter, I assume u modify it accordingly. It returns the number of bookings

the recordset example is like this


Dim username As String
Dim strSQL As String
Dim rs as dao.recordset
Dim lCount as long


strSQL = "SELECT Count(*) AS numberOfBookings FROM tblBooking WHERE userId = username AND jobStatus = open "
set rs=currentdb.openrecordset (strSQL)
lCount = 0
if rs.eof = false then
rs.movelast
lCount = rs.RecordCount
endif
rs.close
set rs=nothing


If lCount <= 15 Then
MsgBox "You have 15 or more open bookings, please close bookings before proceeding"




i thinh在上面的Qry中没有使用count(*)



i thinh in the above Qry there is no use of count(*)



u不能使用RunSQL,因为这是用于动作查询,而是使用记录集或域函数


例如域函数 - DCOUNT


DCOUNT(" *"," tblBooking"," userid = username AND jobStatus = open")


以上示例带您的过滤器,我假设您修改因此。它返回预订的数量


记录集示例是这样的


Dim用户名字符串

Dim strSQL As String

Dim rs as dao.recordset

Dim lCount as


strSQL = SELECT Count(*)AS numberOfBookings FROM tblBooking WHERE userId = username AND jobStatus = open"

set rs = currentdb.openrecordset(strSQL)

lCount = 0

如果rs.eof = false那么

rs.movelast

lCount = rs.RecordCount

endif

rs.close

set rs = nothing


如果lCount< = 15那么

MsgBox您有15个或更多的公开预订,请在继续之前关闭预订
u cannot use RunSQL as this is for action queries, instead use a recordset or a domain function

eg domain function - DCOUNT

DCOUNT("*","tblBooking","userid = username AND jobStatus = open")

example above takes your filter, I assume u modify it accordingly. It returns the number of bookings

the recordset example is like this


Dim username As String
Dim strSQL As String
Dim rs as dao.recordset
Dim lCount as long


strSQL = "SELECT Count(*) AS numberOfBookings FROM tblBooking WHERE userId = username AND jobStatus = open "
set rs=currentdb.openrecordset (strSQL)
lCount = 0
if rs.eof = false then
rs.movelast
lCount = rs.RecordCount
endif
rs.close
set rs=nothing


If lCount <= 15 Then
MsgBox "You have 15 or more open bookings, please close bookings before proceeding"



它只会选择一条记录。如果你给了


lCount = rs.RecordCount


那么价值将是1


你可以这样使用

lCount = rs.field(" numberOfBookings")


it will select only one record. if you give

lCount = rs.RecordCount

then the value will be 1

beter you can use like this
lCount = rs.field("numberOfBookings")


这篇关于计算记录以显示错误消息。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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