正确使用IsNull(A2K3) [英] Proper use of IsNull (A2K3)

查看:63
本文介绍了正确使用IsNull(A2K3)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


我使用下面的代码进入调试模式,varReturnVal为Null,但

代码仍在运行。


知道为什么吗?


Dim varReturnVal As Variant

Dim intDogID As Integer


intDogID = Me.txtDogID

varReturnVal = DLookup(" [tDogPicLoc]",dogs",[iDog_ID] ="&

intDogID)


如果IsNull(varReturnVal)那么

Me.imgDogPic.Picture ="" ''< - 此代码运行虽然

varReturnVal在debug中为Null

否则

Me.imgDogPic.Picture = varReturnVal

结束如果


End Sub

Hi All,

I go into debug mode with the code below and varReturnVal is Null, but
the code still is run.

Any idea why?

Dim varReturnVal As Variant
Dim intDogID As Integer

intDogID = Me.txtDogID

varReturnVal = DLookup("[tDogPicLoc]", "dogs", "[iDog_ID]= " &
intDogID)

If IsNull(varReturnVal) Then
Me.imgDogPic.Picture = "" '' <-- This code runs although
varReturnVal in debug is Null
Else
Me.imgDogPic.Picture = varReturnVal
End If

End Sub

推荐答案

一些要点。


我希望你的iDog_ID应该是一个自动编号(长)

所以将intDogID定义为整数是一个冲突

我怀疑line intDogID = Me.txtDogID应该是LngDogID =

CLng(txtDogID)

看看Allen Browne的网站 http://allenbrowne.com/ser-42.html

这个要快得多DLookup的版本,虽然它看起来有点

复杂只是使用它的内容DLookup

所以你的行应该读取


varReturnVal = ELookup(tDogPicLoc,dog,iDog_ID ="& LngDogID)

假设你是loa将图片转换为图像控件,如果没有

图像,则图片为(无),以便if子句应为


If IsNull(varReturnVal )然后

Me.imgDogPic.Picture ="(none)" ''< - 此代码运行虽然

varReturnVal在debug中为Null

否则

Me.imgDogPic.Picture = varReturnVal

结束如果


Phil


" PW" < pa ********************** @ removehotmail.comwrote in message

news:nq ******** ************************ @ 4ax.com ...
A number of points.

I would expect your iDog_ID should be an AutoNumber (Long)
So defining intDogID as an integer is a conflict
I supect that the line intDogID = Me.txtDogID should be LngDogID =
CLng(txtDogID)
Have a look at Allen Browne''s website http://allenbrowne.com/ser-42.html
This is a much faster version of DLookup and although it appears a bit
complicated just use it inslead of DLookup
so your line should read

varReturnVal = ELookup("tDogPicLoc", "dogs", "iDog_ID = " & LngDogID)
Assuming you are loading the picture into an Image Control, if there is no
image the picture is (none) so that the if clause should be

If IsNull(varReturnVal) Then
Me.imgDogPic.Picture = "(none)" '' <-- This code runs although
varReturnVal in debug is Null
Else
Me.imgDogPic.Picture = varReturnVal
End If

Phil

"PW" <pa**********************@removehotmail.comwrote in message
news:nq********************************@4ax.com...

大家好,


我使用下面的代码进入调试模式,varReturnVal为Null,但

代码仍在运行。


任何想法为什么?


Dim varReturnVal As Variant

Dim intDogID As Integer


intDogID = Me .txtDogID

varReturnVal = DLookup(" [tDogPicLoc]"," dogs"," [iDog_ID] ="&

intDogID )


如果是IsNull(varReturnVal)那么

Me.imgDogPic.Picture ="" ''< - 此代码运行虽然

varReturnVal在debug中为Null

否则

Me.imgDogPic.Picture = varReturnVal

结束如果


结束次级
Hi All,

I go into debug mode with the code below and varReturnVal is Null, but
the code still is run.

Any idea why?

Dim varReturnVal As Variant
Dim intDogID As Integer

intDogID = Me.txtDogID

varReturnVal = DLookup("[tDogPicLoc]", "dogs", "[iDog_ID]= " &
intDogID)

If IsNull(varReturnVal) Then
Me.imgDogPic.Picture = "" '' <-- This code runs although
varReturnVal in debug is Null
Else
Me.imgDogPic.Picture = varReturnVal
End If

End Sub



2008年10月23日星期四09:09:39 +0100,Phil Stanton

< ph ** @ myfamilyname.co.ukwrote:
On Thu, 23 Oct 2008 09:09:39 +0100, "Phil Stanton"
<ph**@myfamilyname.co.ukwrote:

> ;一些要点。

我希望你的iDog_ID应该是一个自动编号(长)
>A number of points.

I would expect your iDog_ID should be an AutoNumber (Long)



如果我知道我在做什么那么,它本来是一个

自动编号,但是我把它变成了一个整数并用代码手动更新

:-)


感谢您的提示!


我不知道为什么DLookup的返回值= Null但是

IsNull代码仍在运行! br />

任何人的想法吗?


-paul

If I knew what I was doing way back then, it would have been an
AutoNumber, but I made it an integer and update it manually in code
:-)

Thanks for the tip though!

I have no idea why the return value from the DLookup = Null but the
IsNull code still runs!

Any ideas anyone?

-paul


> ;因此将intDogID定义为整合呃是冲突
我认为行intDogID = Me.txtDogID应该是LngDogID =
CLng(txtDogID)
看看Allen Browne的网站 http://allenbrowne.com/ser-42.html
这是一个快得多的DLookup的版本,虽然看起来有点复杂,但只需使用它就可以了解DLookup
所以你的行应该读取

varReturnVal = ELookup(" tDogPicLoc"," dogs" ,iDog_ID = &安培; LngDogID)

假设您正在将图片加载到图像控件中,如果没有图片,则图片为(无),以便if子句应该是

如果是IsNull(varReturnVal)那么

Me.imgDogPic.Picture ="(none)" ''< - 此代码运行虽然调试中的varReturnVal为Null

否则

Me.imgDogPic.Picture = varReturnVal

结束如果

Phil

PW < pa ********************** @ removehotmail.comwrote in message
新闻:nq ************ ********************@4ax.com ..
>So defining intDogID as an integer is a conflict
I supect that the line intDogID = Me.txtDogID should be LngDogID =
CLng(txtDogID)
Have a look at Allen Browne''s website http://allenbrowne.com/ser-42.html
This is a much faster version of DLookup and although it appears a bit
complicated just use it inslead of DLookup
so your line should read

varReturnVal = ELookup("tDogPicLoc", "dogs", "iDog_ID = " & LngDogID)
Assuming you are loading the picture into an Image Control, if there is no
image the picture is (none) so that the if clause should be

If IsNull(varReturnVal) Then
Me.imgDogPic.Picture = "(none)" '' <-- This code runs although
varReturnVal in debug is Null
Else
Me.imgDogPic.Picture = varReturnVal
End If

Phil

"PW" <pa**********************@removehotmail.comwrote in message
news:nq********************************@4ax.com.. .

>大家好,

我使用下面的代码进入调试模式,varReturnVal为Null,但是代码是
仍在运行。

任何想法为什么?

Dim varReturnVal As Variant
Dim intDogID As Integer

intDogID = Me.txtDogID

varReturnVal = DLookup(" [tDogPicLoc]",dogs",[iDog_ID] ="&
intDogID)

如果是IsNull (varReturnVal)然后
Me.imgDogPic.Picture ="" ''< - 此代码运行虽然调试中的varReturnVal为Null
否则
Me.imgDogPic.Picture = varReturnVal
结束如果

结束Sub
>Hi All,

I go into debug mode with the code below and varReturnVal is Null, but
the code still is run.

Any idea why?

Dim varReturnVal As Variant
Dim intDogID As Integer

intDogID = Me.txtDogID

varReturnVal = DLookup("[tDogPicLoc]", "dogs", "[iDog_ID]= " &
intDogID)

If IsNull(varReturnVal) Then
Me.imgDogPic.Picture = "" '' <-- This code runs although
varReturnVal in debug is Null
Else
Me.imgDogPic.Picture = varReturnVal
End If

End Sub


10月23日,7:56 * pm,PW< paulremove_williamson ... @ removehotmail.com>

写道:
On Oct 23, 7:56*pm, PW <paulremove_williamson...@removehotmail.com>
wrote:

On Thu,2008年10月23日09:09:39 +0100,Phil Stanton


< p ... @ myfamilyname.co.ukwrote:
On Thu, 23 Oct 2008 09:09:39 +0100, "Phil Stanton"

<p...@myfamilyname.co.ukwrote:

多个积分。
A number of points.


我希望你的iDog_ID应该是一个自动编号(长)
I would expect your iDog_ID should be an AutoNumber (Long)



如果我知道我当时正在做什么,它本来是一个

自动编号,但我把它变成了一个整数并用代码手动更新

: - )


感谢您的提示!


我不知道为什么DLookup的返回值= Null但是

IsNull代码仍在运行!


任何人都有想法吗?


-paul


If I knew what I was doing way back then, it would have been an
AutoNumber, but I made it an integer and update it manually in code
:-)

Thanks for the tip though!

I have no idea why the return value from the DLookup = Null but the
IsNull code still runs!

Any ideas anyone?

-paul


因此将intDogID定义为整数是一个冲突

我怀疑行intDogID = Me.txtDogID应该是LngDogID =

CLng(txtDogID)

看看Allen Browne的网站http://allenbrowne.com/ser-42.html

这是一个更快的DLookup版本,虽然看起来有点

复杂只需使用它就是DLookup

所以你的行应该是
So defining intDogID as an integer is a conflict
I supect that the line intDogID = Me.txtDogID should be LngDogID =
CLng(txtDogID)
Have a look at Allen Browne''s websitehttp://allenbrowne.com/ser-42.html
This is a much faster version of DLookup and although it appears a bit
complicated just use it inslead of DLookup
so your line should read


varReturnVal = ELookup(" tDogPicLoc"," dogs"," iDog_ID =" &安培; LngDogID)

假设您正在将图片加载到图像控件中,如果没有

图像,则图片为(无),因此if子句应为
varReturnVal = ELookup("tDogPicLoc", "dogs", "iDog_ID = " & LngDogID)
Assuming you are loading the picture into an Image Control, if there isno
image the picture is (none) so that the if clause should be


If IsNull(varReturnVal)Then

* * * * Me.imgDogPic.Picture ="(none)" * *''< - 这*代码运行*虽然

varReturnVal在调试中是空的

否则

* * Me.imgDogPic。 Picture = varReturnVal

结束如果
If IsNull(varReturnVal) Then
* * * *Me.imgDogPic.Picture = "(none)" * * '' <-- This *code runs *although
varReturnVal in debug is Null
Else
* *Me.imgDogPic.Picture = varReturnVal
End If


Phil
Phil


" PW" < paulremove_williamson ... @ removehotmail.comwrote in message

news:nq *************************** ***** @ 4ax.com ...
"PW" <paulremove_williamson...@removehotmail.comwrote in message
news:nq********************************@4ax.com...

Hi All,
Hi All,


我使用下面的代码进入调试模式,varReturnVal为Null,但

代码仍在运行。
I go into debug mode with the code below and varReturnVal is Null, but
the code still is run.


知道为什么?
Any idea why?


Dim varReturnVal As Variant

Dim intDogID As Integer
Dim varReturnVal As Variant
Dim intDogID As Integer


intDogID = Me.txtDogID
intDogID = Me.txtDogID


varReturnVal = DLookup(" [tDogPicLoc]",dogs",[iDog_ID] ="&

intDogID)
varReturnVal = DLookup("[tDogPicLoc]", "dogs", "[iDog_ID]= " &
intDogID)


If IsNull(varReturnVal)Then

* * Me.imgDogPic.Picture ="" * *''< - 这*代码运行*虽然

varReturnVal在调试中是空的

否则

* * Me.imgDogPic。 Picture = varReturnVal

结束如果
If IsNull(varReturnVal) Then
* *Me.imgDogPic.Picture = "" * * '' <-- This *code runs *although
varReturnVal in debug is Null
Else
* *Me.imgDogPic.Picture = varReturnVal
End If


End Sub-Hide引用text -
End Sub- Hide quoted text -



- 显示引用的文字 -


- Show quoted text -



这是因为dlookup返回null。请记住,

变体将接受null作为值,而类型变量则不会。

如果iDog_ID和intDogID的类型不匹配dlookup可以

无论如何返回null,所以检查你是否也输入了

iDogID字段作为整数,以匹配intDogID。


我不会太担心dlookup的速度,除非你有一台老旧的慢机器 - 它在大多数情况下都是完全可以的,尽管

艾伦的elookup确实提高了一两个其他的东西以及速度。

如果dlookup工作正常没有褶边,那么就不要去

使用elookup的复杂性。


代码中的一个主要缺点是,在可能的情况下,最好使用类型变量。用nz包装dlookup,如在 -


dim varReturnVal as string

varReturnVal = nz(dLookup(" tDogPicLoc"," dogs",&q) uot; iDog_ID =

" &安培; LngDogID))


然后你可以测试


如果len(varReturnVal)= 0那么

我。 imgDogPic.Picture ="(none)"

Else

Me.imgDogPic.Picture = varReturnVal

结束如果


最后,如果您有机会将iDog_ID

字段输入为表中的文本(默认值),您将永远得到a
返回
null。是的,即使在现阶段也可以更好地将iDog_ID转换为自动编号字段。


Dave


It''s happening because the dlookup is returning a null. Remember, a
variant will accept a null as a value, whereas a typed variable won''t.
If the types of iDog_ID and intDogID don''t match the dlookup could
well return a null regardless, so check that you''ve also typed the
iDogID field as an integer, to match intDogID.

I wouldn''t worry too much about the speed of dlookup unless you have
an old, slow machine - it''s perfectly ok in most cases, although
Allen''s elookup does improve one or two other things as well as speed.
If dlookup works ok without the frilly bits then don''t go to the
complication of using elookup.

One of the main deficiencies in your code is that it is always best to
use typed variables where possible and wrap dlookup with nz, as in -

dim varReturnVal as string
varReturnVal =nz(dLookup("tDogPicLoc", "dogs", "iDog_ID =
" & LngDogID))

You can then test with

If len(varReturnVal) =0 Then
Me.imgDogPic.Picture = "(none)"
Else
Me.imgDogPic.Picture = varReturnVal
End If

Finally, and a long shot, if you''ve by some chance left the iDog_ID
field typed as text (the default) in the table you''ll always get a
null returned. And yes, it would be better even at this stage to
convert iDog_ID into an autonumber field.

Dave


这篇关于正确使用IsNull(A2K3)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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