If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
requiring non null field values in a form or query
Is there any way I can require that a field have a non-null value in a form
or query? I know how to do this in a table definition by setting the Required property to Yes, but I don't want to do this in the table definition. I need to do it in either a form or query. Any suggestions about this? Thanks in advance, Paul |
#2
|
|||
|
|||
requiring non null field values in a form or query
Paul, you could set the before update event of the form to check the field.
Private Sub Form_BeforeUpdate(Cancel As Integer) If IsNull(Me.MyControl) Then MsgBox "Can't be null" Cancel = True Me.MyControl.Setfocus End If End Sub -- Reggie ---------- "Paul James" wrote in message ... Is there any way I can require that a field have a non-null value in a form or query? I know how to do this in a table definition by setting the Required property to Yes, but I don't want to do this in the table definition. I need to do it in either a form or query. Any suggestions about this? Thanks in advance, Paul |
#3
|
|||
|
|||
requiring non null field values in a form or query
Thanks for your help with this, Reggie.
A question: do I need to be concerned with zero-length strings, or will If IsNull(Me.MyControl) work for those as well? Paul |
#4
|
|||
|
|||
requiring non null field values in a form or query
Paul, If your field allows zero length strings change your statement to
If IsNull(Me.MyControl) Or Me.MyControl = "" -- Reggie ---------- "Paul James" wrote in message ... Thanks for your help with this, Reggie. A question: do I need to be concerned with zero-length strings, or will If IsNull(Me.MyControl) work for those as well? Paul |
#5
|
|||
|
|||
requiring non null field values in a form or query
A shorter way to check both zero-length string and Null is this:
If Len(Me.MyControl & "") = 0 Then ' the value is either Null or empty string Else ' the value is not Null and not empty string End If -- Ken Snell MS ACCESS MVP "Reggie" wrote in message ... Paul, If your field allows zero length strings change your statement to If IsNull(Me.MyControl) Or Me.MyControl = "" -- Reggie ---------- "Paul James" wrote in message ... Thanks for your help with this, Reggie. A question: do I need to be concerned with zero-length strings, or will If IsNull(Me.MyControl) work for those as well? Paul |
#6
|
|||
|
|||
Many thanks to Dale, Reggie and Ken
Thanks, guys.
Paul |
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Filtering records in a form based on data in a subform or query. | jbuck | Using Forms | 0 | August 5th, 2004 02:51 PM |
Null Query Field | Brook | Running & Setting Up Queries | 2 | June 25th, 2004 01:22 PM |
Access inconsistencies | Hoopie | Running & Setting Up Queries | 2 | June 15th, 2004 10:53 AM |
Recordset in subform based on field in parent form | Lyn | General Discussion | 15 | June 14th, 2004 03:10 PM |