Null Entries

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have 2 parameters, which one does not allow Null Entry - "Month" and the
otherone is NRIC No. which can allow null entry. Just can't figure out why
it's not successful.

Below is my code
Private Sub cmdOk_Click()
If IsNull(Month) Or (NRICNo) Or (NRICNo) Is Null Then
MsgBox "You must enter the month."
Exit Sub
End If
 
Don't use Month as a field, control, or variable name! It's a VBA function,
and one of many reserved words in ACCESS. See these articles for more
information:

List of reserved words in Access 2002 and Access 2003
http://support.microsoft.com/default.aspx?scid=kb;en-us;286335

List of Microsoft Jet 4.0 reserved words
http://support.microsoft.com/?id=321266

Special characters that you must avoid when you work with Access databases
http://support.microsoft.com/?id=826763



Try this:

If Len(TheMonth & "") = 0 Then
MsgBox "You must enter the month."
Exit Sub
End If
 
I have 2 parameters, which one does not allow Null Entry - "Month" and the
otherone is NRIC No. which can allow null entry. Just can't figure out why
it's not successful.

Below is my code
Private Sub cmdOk_Click()
If IsNull(Month) Or (NRICNo) Or (NRICNo) Is Null Then
MsgBox "You must enter the month."
Exit Sub
End If

Just to note - if NRICNo is anything other than a 0, the IF statement
will be TRUE since it will interpret the second OR clause (NRICNo) as
a logical expression - and it will be false only if the value in the
field is 0.

I'm not at all sure what you intended by the expression but it's NOT
just testing for a null [Month]!

John W. Vinson[MVP]
 
John, show should I write the code in a way that the NRIC No field can be a
Null entry and return all the values if I key in the month, which is not
supposed to be a null entry? Btw, NRIC No. is a text field



John Vinson said:
I have 2 parameters, which one does not allow Null Entry - "Month" and the
otherone is NRIC No. which can allow null entry. Just can't figure out why
it's not successful.

Below is my code
Private Sub cmdOk_Click()
If IsNull(Month) Or (NRICNo) Or (NRICNo) Is Null Then
MsgBox "You must enter the month."
Exit Sub
End If

Just to note - if NRICNo is anything other than a 0, the IF statement
will be TRUE since it will interpret the second OR clause (NRICNo) as
a logical expression - and it will be false only if the value in the
field is 0.

I'm not at all sure what you intended by the expression but it's NOT
just testing for a null [Month]!

John W. Vinson[MVP]
 
John, show should I write the code in a way that the NRIC No field can be a
Null entry and return all the values if I key in the month, which is not
supposed to be a null entry? Btw, NRIC No. is a text field

I don't understand, fel.

Your VBA code is not a query and doesn't "return" any values.

What's the context? If you're running a Query, or opening a form or
report based on a Query, you can simply use no criterion on NRIC No;
all records will be returned, whether or not that field is NULL.

John W. Vinson[MVP]
 
John, my apologies for the confusion. I had tried extracting the code from
somewhere else but it just doesn't seem to work on my parameters.

I am running a query with parameters in a dialog box. A value is required
in the month and the Identification No. is optional. I must then key in a
Identification No. and month. With this, only the selected record is being
retrieved, But what I need is that when I key in the month and not the
Identification No., it shows all records given for the month I had selected.
 
John, I managed to figure out the query by referring to 1 of your post out
there.
It goes, Like IIf([Forms]![Payslip]![NRICNo] Is
Null,"*",[Forms]![Payslip]![NRICNo])
This works fine in my query which retrieve all records when no value is
keyed in. But it doesn't for my parameter for my dialog box.

Sorry for the trouble.
 
Back
Top