473,287 Members | 1,960 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,287 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 2908
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...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

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.