473,387 Members | 1,844 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Required field on a form

Hello All,

Hope someone can help me on my required field problems.
I have a form base on a table for users to input new Employees. There
are 4 fields that cannot be Null when entering new records. (but on
the table, I have these 4 field set up as "Required = No"). I want the
codes to be able to check if the 4 fields are null, if is null, tell
the user to input the null field(s), after the user input the required
field, then ask if want to save the new entry.

On the form's Before Update Event Procedure, I have the following code
on VB. However, after input new records, the check for null field
works, but after it tells me the field is null, it prompts if I want to
save then the form is closed and I don't have a chance to input the
required fields.

Would you please help me what codes should I use, so I can input the
info after it tells me that the field is null?

Your help is greatly appreciated!!

***********Code Begins***********************************
Private Sub Form_BeforeUpdate(Cancel As Integer)
If IsNull(Me.MARSuserID) Or Me.MARSuserID = 0 Then
Call MsgBox("You need to get the ""MARS userID"" from MARS. " _
& vbCrLf & "" _
, vbExclamation, "ENTRY REQUIRED")
Me.MARSuserID.SetFocus
'Exit Sub
End If
If IsNull(Me.SSN) Or Me.SSN = 0 Then
Call MsgBox("You need to enter the ""Social Security No."". " _
& vbCrLf & "" _
, vbExclamation, "ENTRY REQUIRED")
Me.SSN.SetFocus
'Exit Sub
End If
If IsNull(Me.Position) Or Me.Position = 0 Then
Call MsgBox("You need to select a ""PAID AS"" from the list
Provided. " _
& vbCrLf & "" _
, vbExclamation, "ENTRY REQUIRED")
Me.Position.SetFocus
'Exit Sub
End If
If IsNull(Me.DistCode) Or Me.DistCode = 0 Then
Call MsgBox("You need to select a ""Distric Code"" from the list
provided. " _
& vbCrLf & "" _
, vbExclamation, "ENTRY REQUIRED")
Me.DistCode.SetFocus
'Exit Sub
End If
If MsgBox("Do You Want To Save Your Changes?", vbYesNo + vbQuestion) =
vbNo Then
Cancel = True
Me.Undo
End If
End Sub
*****************Code Ends**************************
Orchid

Nov 13 '05 #1
3 2912
Orchid wrote:
Hello All,

Hope someone can help me on my required field problems.
I have a form base on a table for users to input new Employees. There
are 4 fields that cannot be Null when entering new records. (but on
the table, I have these 4 field set up as "Required = No"). I want the
codes to be able to check if the 4 fields are null, if is null, tell
the user to input the null field(s), after the user input the required
field, then ask if want to save the new entry.

On the form's Before Update Event Procedure, I have the following code
on VB. However, after input new records, the check for null field
works, but after it tells me the field is null, it prompts if I want to
save then the form is closed and I don't have a chance to input the
required fields.

Would you please help me what codes should I use, so I can input the
info after it tells me that the field is null?

Your help is greatly appreciated!!

***********Code Begins***********************************
Private Sub Form_BeforeUpdate(Cancel As Integer)
If IsNull(Me.MARSuserID) Or Me.MARSuserID = 0 Then
Call MsgBox("You need to get the ""MARS userID"" from MARS. " _
& vbCrLf & "" _
, vbExclamation, "ENTRY REQUIRED")
Me.MARSuserID.SetFocus
'Exit Sub
End If
If IsNull(Me.SSN) Or Me.SSN = 0 Then
Call MsgBox("You need to enter the ""Social Security No."". " _
& vbCrLf & "" _
, vbExclamation, "ENTRY REQUIRED")
Me.SSN.SetFocus
'Exit Sub
End If
If IsNull(Me.Position) Or Me.Position = 0 Then
Call MsgBox("You need to select a ""PAID AS"" from the list
Provided. " _
& vbCrLf & "" _
, vbExclamation, "ENTRY REQUIRED")
Me.Position.SetFocus
'Exit Sub
End If
If IsNull(Me.DistCode) Or Me.DistCode = 0 Then
Call MsgBox("You need to select a ""Distric Code"" from the list
provided. " _
& vbCrLf & "" _
, vbExclamation, "ENTRY REQUIRED")
Me.DistCode.SetFocus
'Exit Sub
End If
If MsgBox("Do You Want To Save Your Changes?", vbYesNo + vbQuestion) =
vbNo Then
Cancel = True
Me.Undo
End If
End Sub
*****************Code Ends**************************
Orchid

You forgot to Cancel the operation. Ex:
If IsNull(Field) Then
Msgbox "Put some data in the Field"
Me.Field.SetFocus
Cancel = True
Endif
Nov 13 '05 #2
Thanks for your reply!
I add Cancel=True, but still have the same problem. What did I miss?
Please help... Thanks!

Nov 13 '05 #3
Orchid wrote:
Thanks for your reply!
I add Cancel=True, but still have the same problem. What did I miss?
Please help... Thanks!

Are you closing the form when the Cancel fails? As in adding some data,
then pressing the X button on the window?

If so, it will execute your BeforeUpdate event and then continue with
closing the form. If that is the case then you might want to enter
something like this...

Private Sub Form_Error(DataErr As Integer, Response As Integer)
If DataErr = 2169 Then SendKeys "{Right}{Enter}"
End Sub

This is what my code may look like
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim strMsg As String

If IsNull(Me.MARSuserID) Or Me.MARSuserID = 0 Then
strMsg = "You need to get the ""MARS userID"" from MARS."
Me.MARSuserID.SetFocus
elseif IsNull(Me.SSN) Or Me.SSN = 0 Then
strMsg = "You need to enter the ""Social Security No."".
Me.SSN.SetFocus
elseIf IsNull(Me.Position) Or Me.Position = 0 Then
strMsg = "You need to select a ""PAID AS"" from the list
Provided."
Me.Position.SetFocus
elseif IsNull(Me.DistCode) Or Me.DistCode = 0 Then
strMsg = "You need to select a ""Distric Code"" from the list
provided."
Me.DistCode.SetFocus
End If

If strMsg > "" THen
msgbox strMsg,,"Entry Required"
Cancel = True
ElseIf MsgBox("Do You Want To Save Your Changes?", _
vbYesNo + vbQuestion) = vbNo Then
Cancel = True
Me.Undo
endif
End Sub
Nov 13 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Mark Creelman | last post by:
Hi: I am relatively new to ASP. I prefer Perl, but need to do this form to e-mail sipt for a web page, See Example of script below that works fine. I want to add the feature to this where it...
2
by: MrMike | last post by:
Hi. I have a webform with a two required field validators. I have a cancel button on the form which should allow the user to quit the form and Response.Redirect to a previous webform. However,...
1
by: Deborah V. Gardner | last post by:
I have a form frmViolations with a subform sfrmViolations. There is a one-to-many relationship between the two. On the subform I have a date field and a duration field. Both can be blank but if...
16
by: Georges Heinesch | last post by:
Hi. My form contains a control (cboFooBar), which has an underlying field with the "Required" property set to "Yes". Now, while filling out all the controls of the form, I have to fill out this...
3
by: Mark | last post by:
Access97 --- I set the Required property for a field at the table level and I have a form that contains that field. When I click the Close button at the top left of the screen, I get an error...
2
by: bufbec1 | last post by:
I am pretty good with Access, but do not understand VBA. I have researched this topic and see only VBA answers, so I hope someone can help with my specific question. I have 2 fields for an...
3
by: Rick | last post by:
I have an interesting problem when I run the following code in Netscape (7.02) vs. IE. This page works great in IE and all my controls bring up the validation summary dialog box if the required...
2
by: Del | last post by:
I have a popup form that consist of a single field called EnteredBy and a Subform that has three fields. The popup form also has a button in the Form Footer called close. In the On Click event I...
37
by: viki1967 | last post by:
Hi all. I have this simple form. I need if checkbox C_1 is selected: 1) field name="n_1" is required and accept only numbers; 2) field name="n_2" is required and accept only numbers; I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.