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 » General Discussion
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Require fields



 
 
Thread Tools Display Modes
  #1  
Old July 7th, 2009, 09:40 PM posted to microsoft.public.access
Jessica
external usenet poster
 
Posts: 299
Default Require fields

I have a field call p structure which is a dropdown and one call p revised
date. When some one makes a selection on the p structure field i would like
the p revised date field to be a require field. How can i do it?
  #2  
Old July 7th, 2009, 10:09 PM posted to microsoft.public.access
Beetle
external usenet poster
 
Posts: 1,254
Default Require fields

Assuming you are using a form for data entry (you should be)
and not working directly in the table (you shouldn't be),
you would use code like the following in the Before Update
event of the form (substitute your actual control names);

Private Sub Form_BeforeUpdate(Cancel As Integer)

If Not IsNull(Me![p structure]) Then
If IsNull(Me![p revised]) Then
MsgBox "Please enter a Revised Date"
Cancel = True
End If
End If

End Sub

--
_________

Sean Bailey


"Jessica" wrote:

I have a field call p structure which is a dropdown and one call p revised
date. When some one makes a selection on the p structure field i would like
the p revised date field to be a require field. How can i do it?

  #3  
Old July 7th, 2009, 10:20 PM posted to microsoft.public.access
Arvin Meyer MVP
external usenet poster
 
Posts: 640
Default Require fields

In a form (it cannot be done in a table) a bit of code something like
(untested)

Private Sub p_structure_AfterUpdate()
If Len(Me.[p structure] & vbNullString) 0 Then
MsgBox "You must fill in p revised date", vbOKOnly, "Required"
Me.[p revised date].SetFocus
End If
End Sub

and then:

Private Sub Form_BeforeUpdate(Cancel As Integer)
If Len(Me.[p structure] & vbNullString) 0 and If Len(Me.[p revised
date] & vbNullString) = 0 Then
MsgBox "The date in p revised date is REQUIRED"
Cancel = True
End If
End Sub

Now they must either delete the data in p structure or add the data in p
revised date.
--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.mvps.org/access
http://www.accessmvp.com

"Jessica" wrote in message
...
I have a field call p structure which is a dropdown and one call p revised
date. When some one makes a selection on the p structure field i would
like
the p revised date field to be a require field. How can i do it?



  #4  
Old July 7th, 2009, 11:10 PM posted to microsoft.public.access
Clifford Bass[_2_]
external usenet poster
 
Posts: 1,295
Default Require fields

Hi Jessica,

If you want to do it in the table you could use the table-level
Validation Rule property (right-click the table window while in design mode
and choose Properties). Set it to:

(IsNull([p structure]) And IsNull([p revised])) Or (Not IsNull([p
structure]) And Not IsNull([p revised]))

This assumes that if [p structure] is null [p revised] should be null
also. If that is not the case and you allow [p structure] to be null while
[p revised] is not null then use:

IsNull([p structure]) Or (Not IsNull([p structure]) And Not IsNull([p
revised]))

You can use the Validation Text property to provide a meaningful message.

Clifford Bass

"Jessica" wrote:

I have a field call p structure which is a dropdown and one call p revised
date. When some one makes a selection on the p structure field i would like
the p revised date field to be a require field. How can i do it?

  #5  
Old July 8th, 2009, 03:31 PM posted to microsoft.public.access
Jessica
external usenet poster
 
Posts: 299
Default Require fields

if i already have the below for another field can i have two event procedures?

Private Sub Form_BeforeUpdate(Cancel As Integer)
If Not IsNull(Me![Closing Date]) Then
If Nz(Me![Exit Reason], "") = "" Then
MsgBox " You must choose an exit reason"
Cancel = True
Me![Exit Reason].SetFocus
End If
End If
End Sub


"Beetle" wrote:

Assuming you are using a form for data entry (you should be)
and not working directly in the table (you shouldn't be),
you would use code like the following in the Before Update
event of the form (substitute your actual control names);

Private Sub Form_BeforeUpdate(Cancel As Integer)

If Not IsNull(Me![p structure]) Then
If IsNull(Me![p revised]) Then
MsgBox "Please enter a Revised Date"
Cancel = True
End If
End If

End Sub

--
_________

Sean Bailey


"Jessica" wrote:

I have a field call p structure which is a dropdown and one call p revised
date. When some one makes a selection on the p structure field i would like
the p revised date field to be a require field. How can i do it?

  #6  
Old July 8th, 2009, 11:02 PM posted to microsoft.public.access
John W. Vinson
external usenet poster
 
Posts: 18,261
Default Require fields

On Wed, 8 Jul 2009 07:31:01 -0700, Jessica
wrote:

if i already have the below for another field can i have two event procedures?

Private Sub Form_BeforeUpdate(Cancel As Integer)
If Not IsNull(Me![Closing Date]) Then
If Nz(Me![Exit Reason], "") = "" Then
MsgBox " You must choose an exit reason"
Cancel = True
Me![Exit Reason].SetFocus
End If
End If
End Sub


The Form can have only one BeforeUpdate event, but that event can check any
number of controls.

--

John W. Vinson [MVP]
 




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


All times are GMT +1. The time now is 09:16 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.