UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> Way To Create Custom Error Message In Required Fields, Access 2016    
 
   
mesh3l09
post May 23 2019, 04:01 AM
Post#1



Posts: 5
Joined: 23-May 19



hi guys ,,

as the subject shown ,

i have form in access 2016 , and i have required fields and i want Replacing a Standard Microsoft Access Error Message with a Custom Error Message

from ("you must enter a value in the 'Table1.Email' field")

to ( "please enter your email")



thank you ,,
Go to the top of the page
 
June7
post May 23 2019, 05:15 AM
Post#2



Posts: 618
Joined: 25-January 16



Use form BeforeUpdate event to validate data. Common topic, many examples can be found.

--------------------
Attach File Manager is below Advanced editor window, click Go Advanced below Quick Reply window. To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.
DEBUG! DEBUG! DEBUG! http://www.cpearson.com/Excel/DebuggingVBA.aspx
Go to the top of the page
 
mesh3l09
post May 23 2019, 05:54 AM
Post#3



Posts: 5
Joined: 23-May 19



should i put the field required in the table ?
Go to the top of the page
 
BruceM
post May 23 2019, 06:38 AM
Post#4


UtterAccess VIP
Posts: 7,892
Joined: 24-May 10
From: Downeast Maine


Your question is unclear. A required field would have to be in the table upon which the form is based. It could be in a query based on the table, but that doesn't change the process.

A simple way to perform validation could be something like this:

CODE
Private Sub Form_BeforeUpdate (Cancel As Integer)

  If IsNull(Me.txtEmail) Then
      MsgBox "Email is required"
      Cancel = True
      Exit Sub
  End If

  If IsNull(Me.SomeOtherControl) Then
      MsgBox ....
      Cancel = True
      Exit Sub
  End If

End Sub

This approach can be cumbersome if a lot of controls need to be validated, but no matter the approach, setting Cancel to True in the form's Before Update event cancels the update (that is, the record is not saved). As June7 pointed out, there are numerous examples of different approaches to data validation.

Go to the top of the page
 
theDBguy
post May 23 2019, 06:53 AM
Post#5


Access Wiki and Forums Moderator
Posts: 75,606
Joined: 19-June 07
From: SunnySandyEggo


Hi,

Welcome to UtterAccess!
welcome2UA.gif

Another approach you could try, although I prefer the previously suggested one as well, is to play with the Form’s Error event.

--------------------
Just my 2 cents... "And if I claim to be a wise man, it surely means that I don't know" - Kansas
Access Website | Access Blog | Email
Go to the top of the page
 
projecttoday
post May 23 2019, 07:06 AM
Post#6


UtterAccess VIP
Posts: 10,758
Joined: 10-February 04
From: South Charleston, WV


No, you do not want the field set as required in the table.

--------------------
Robert Crouser
Go to the top of the page
 
gemmathehusky
post May 23 2019, 07:11 AM
Post#7


UtterAccess VIP
Posts: 4,693
Joined: 5-June 07
From: UK


why would you not want "required" set to true in the table?

--------------------
Dave (Male)

(Gemma was my dog)
Go to the top of the page
 
mesh3l09
post May 23 2019, 07:59 AM
Post#8



Posts: 5
Joined: 23-May 19



BruceM :

i mean when user forget to enter the required fields , i want show massage that tel him should to enter this field
Go to the top of the page
 
mesh3l09
post May 23 2019, 08:04 AM
Post#9



Posts: 5
Joined: 23-May 19



thank u guys for Ur answer

i will try all Ur suggestion
Go to the top of the page
 
GroverParkGeorge
post May 23 2019, 08:06 AM
Post#10


UA Admin
Posts: 35,177
Joined: 20-June 02
From: Newcastle, WA


As suggested, you can use the Before Update event of the form to check the contents of the text box for email.

I would use this method rather than IsNull() because it is possible (even if it's unlikely) that a user could enter something in the text control, and then delete it. That would leave it with a zero length string instead of being null.

CODE
Private Sub Form_BeforeUpdate (Cancel As Integer)

  If Len(Me.txtEmail & vbNullString) = 0 Then
      MsgBox "Email is required"
      Cancel = True
      Exit Sub
  End If

End Sub

--------------------
My Real Name Is George. Grover Park Consulting is where I do business.
How to Ask a Good Question
Beginning SQL Server
Go to the top of the page
 
projecttoday
post May 23 2019, 08:42 AM
Post#11


UtterAccess VIP
Posts: 10,758
Joined: 10-February 04
From: South Charleston, WV


QUOTE
why would you not want "required" set to true in the table?


You lose control. (Bear in mind that I never specify "required" so I could be wrong in my conclusion.)

--------------------
Robert Crouser
Go to the top of the page
 
GroverParkGeorge
post May 23 2019, 08:49 AM
Post#12


UA Admin
Posts: 35,177
Joined: 20-June 02
From: Newcastle, WA


This may be one of those philosophical considerations.

I do prefer to push things down to the table if I can because that gives me MORE control over the requirement; I know that the database engine enforces the requirement and there's less opportunity for an invalid entry to slip by validation done in one form without it.

The question of a custom error message about that requirement seems to be a separate issue, IMO.


--------------------
My Real Name Is George. Grover Park Consulting is where I do business.
How to Ask a Good Question
Beginning SQL Server
Go to the top of the page
 
BruceM
post May 23 2019, 09:50 AM
Post#13


UtterAccess VIP
Posts: 7,892
Joined: 24-May 10
From: Downeast Maine


I routinely set text fields not to accept a ZLS unless there is a specific reason to allow it, which has happened only rarely, for reasons I cannot recall at the moment. However, allowing ZLS is the default, I believe, so it needs to be done for every text field.

I think one reason for setting a field as required at the table level is when data are imported into a table. If a field is required, and does not accept a ZLS, it should not be possible to import a record that does not contain a text string longer than 0.
Go to the top of the page
 
jleach
post May 23 2019, 10:02 AM
Post#14


UtterAccess Editor
Posts: 10,011
Joined: 7-December 09
From: St Augustine, FL


It's a two part thing: if the field is required per the data structure, require it on the table.

If the field is required on the table, it makes sense to do a beforeUpdate check on it to validate it on a form so you can show a friendly error message.

Occasionally you'll have a case where it's not required in the table but you want to require it in a form (maybe due to some conditional business logic).

--------------------
Go to the top of the page
 
mesh3l09
post May 27 2019, 03:19 AM
Post#15



Posts: 5
Joined: 23-May 19



thank u guys for all solution

GroverParkGeorge's solution work with me
Go to the top of the page
 


Custom Search


RSSSearch   Top   Lo-Fi    26th June 2019 - 03:09 AM