解决消息“无效使用null” [英] Solve the message "invalid use of null"

查看:687
本文介绍了解决消息“无效使用null”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hai one and all,

Hai one and all,

请指导我解决以下问题

有一个更新学生出勤率的表格。在那个表格中有课程专栏。基于该字段,写有"dlookup"字样。另一个字段的功能是该月的总工作日。

there is a form for updating students attendance. in that form there is column for Course. based on this field there written "dlookup" function for another field that is total working days in that month.

 输入上一个学生详细信息后,如果我转到下一个,我立刻得到"运行时错误94,无效使用null即将到来,vba窗口正在打开。并且在vba代码中有一个黄色标记"txtSep = Me.Course.Value"

 after entering last student details if i go to next, immediately i am getting "Run time error 94, Invalid use of null is coming and the vba window is getting opened. and there is a yellow mark in the vba code "txtSep = Me.Course.Value"

代码是 

请帮助解决这个问题。

推荐答案

嗨AspinR,

Hi AspinR,

出现此错误的原因是wdOct被声明为Integer。如果没有记录满足条件或域不包含任何记录,则DLookup函数返回Null。一个整数不能为空,但变量不能。

The reason for this error is that wdOct is declared as an Integer. If no record satisfies criteria or if domain contains no records, the DLookup function returns a Null. An Integer cannot be Null, but a Variant does.

你必须将wdOct声明为一个变体:

You have to declare wdOct as an Variant:

Dim wdOct As Variant

Dim wdOct As Variant

变体可以包含空值。在您通过DLookUp设置wdOct的值之后,您必须检查wdOct,例如:

A Variant can contain a Null Value. After you set the value for wdOct by DLookUp, you have to check wdOct, for example:

    If IsNull(wdOct) Then
        Exit Sub
    Else
        ' Instructions..
    End If


这篇关于解决消息“无效使用null”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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