Required Fields (1 Viewer)

trucktime

Registered User.
Local time
Today, 15:32
Joined
Oct 24, 2004
Messages
556
In my form there are 3 fields that are required to be filled out.
In the form Before Update I have the following code:

If IsNull([FirstName]) Or IsNull([LastName]) Or IsNull([P_Address]) Then
MsgBox "Required field left empty", vbOKOnly
Cancel = True
End If

Now when I click on the Ok Button in the MsgBox, the form closes.
I want to have it stay open and move the focus to the first required field,
so I can enter the info.
I played with setFocus too, but the form closes no matter what.
What am I doing wrong here? Any help is appreciated.
Checked the forum on this subject, found no solution
Trucktime

Access 2003
 

bdhtexas

Registered User.
Local time
Today, 16:32
Joined
Dec 3, 2003
Messages
79
Here's my situation, I have Access 97

I have a form that users update, but they continue to leave this one field blank and I have to go behind them to enter this date.

Field Name: OrigProcDt

This is a date field

I don't want this field to be a required field in the table, because it won't stop it anyways.

The record is already added by the clerical staff, the other users just update the record when it's time to.

The problem is that they need to enter a date in this field before leaving the record they are updating.

Any help would be appreciated.
 

Ukraine82

Registered User.
Local time
Today, 14:32
Joined
Jun 14, 2004
Messages
346
Check out the attachment.

hth,

Michael
 

Attachments

  • Required.zip
    15.7 KB · Views: 118

bdhtexas

Registered User.
Local time
Today, 16:32
Joined
Dec 3, 2003
Messages
79
I was unable to view your attachment, I got the following error:

"Unrecognized database format"
 

ghudson

Registered User.
Local time
Today, 17:32
Joined
Jun 8, 2002
Messages
6,195
I use this method in all my apps...
Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
On Error GoTo Form_BeforeUpdate_Err

    If IsNull([FirstName]) Or IsNull([LastName]) Or IsNull([P_Address]) Then
        Beep
        MsgBox "Please key a value for each of the required fields.", vbCritical, "Incomplete Data Entry"
        DoCmd.CancelEvent
        Exit Sub
    End If
    
Form_BeforeUpdate_Exit:
    Exit Sub

Form_BeforeUpdate_Err:
    MsgBox Err.Number & " - " & Err.Description
    Resume Form_BeforeUpdate_Exit
    
End Sub
 

Ukraine82

Registered User.
Local time
Today, 14:32
Joined
Jun 14, 2004
Messages
346
My guess is you dont have a new version of access. I attached a 97 version.

hth,

Michael
 

Attachments

  • required97.zip
    9 KB · Views: 92

bdhtexas

Registered User.
Local time
Today, 16:32
Joined
Dec 3, 2003
Messages
79
Ukraine82 said:
My guess is you dont have a new version of access. I attached a 97 version.

hth,

Michael

Doesn't Work, I was able to add new records to the database without any error messages. The only way I got the required field notice is when I clicked New. So, it can be bypassed. I need a way for it not to be bypassed.
 

Ukraine82

Registered User.
Local time
Today, 14:32
Joined
Jun 14, 2004
Messages
346
Try ghudson sample

Private Sub Form_BeforeUpdate(Cancel As Integer)
On Error GoTo Form_BeforeUpdate_Err

If IsNull([OrigProcDt]) Then
Beep
MsgBox "Please key a value for each of the required fields.", vbCritical, "Incomplete Data Entry"
DoCmd.CancelEvent
Exit Sub
End If

Form_BeforeUpdate_Exit:
Exit Sub

Form_BeforeUpdate_Err:
MsgBox Err.Number & " - " & Err.Description
Resume Form_BeforeUpdate_Exit

End Sub

This will stop the user from going to a new record till your OrigProcDt field is completed.

Be sure to paste the code in Form Before_Update.

hth,

Michael
 

Users who are viewing this thread

Top Bottom