A Microsoft Office (Excel, Word) forum. OfficeFrustration

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.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

requiring non null field values in a form or query



 
 
Thread Tools Display Modes
  #1  
Old August 6th, 2004, 05:09 PM
Paul James
external usenet poster
 
Posts: n/a
Default 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  
Old August 6th, 2004, 07:33 PM
Reggie
external usenet poster
 
Posts: n/a
Default 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  
Old August 6th, 2004, 11:33 PM
Paul James
external usenet poster
 
Posts: n/a
Default 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  
Old August 7th, 2004, 12:14 AM
Reggie
external usenet poster
 
Posts: n/a
Default 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  
Old August 7th, 2004, 12:30 AM
Ken Snell
external usenet poster
 
Posts: n/a
Default 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  
Old August 7th, 2004, 01:31 AM
Paul James
external usenet poster
 
Posts: n/a
Default Many thanks to Dale, Reggie and Ken

Thanks, guys.

Paul


 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

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


All times are GMT +1. The time now is 07:09 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.