Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Message box for required fields

Status
Not open for further replies.

mondeoman

MIS
Dec 7, 2006
203
GB
My form is based on a table where fields are required to be filled. If the user moves on to another record the default MS error message box is shown. What I would like is a friendlier message box that showed the field name that needs to be filled and also an instruction that is the user does not wish to complete the record to press escape. I have looked through previous similar questions but non seem to be exactly what I am looking for. Any advice on how I can over write the default error message for a required field and put in my own or alternative modifiy MS's default message?

I have tried the following code in the form's before updae but I get a compile error on ctl.Name:

Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim Msg As String, Style As Integer, Title As String
Dim DL As String, ctl As Control

DL = vbNewLine & vbNewLine

For Each ctl In Me.Controls
If ctl.Tag = "?" Then
If Trim(ctl & "") = "" Then
Msg = "'" & ctl.Name & "' is Required!" & DL & _
"Please enter a value or hit Esc to abort the record . . ."
Style = vbInformation + vbOKOnly
Title = "Required Data Missing! . . ."
MsgBox Msg, Style, Title
ctl.Name.SetFocus
Cancel = True
Exit For
End If
End If
Next
End Sub
 
How are ya mondeoman . . .

I believe its the [blue]SetFocus[/blue] line thats causing the problem:
Code:
[blue]Change: ctl.Name.SetFocus
To    : Me(ctl.Name).Setfocus[/blue]


See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
I was going to suggest the same thing.

It's great that you provide the expression that is causing the compile error but it would help if you told us which line since ctl.Name is used on more than one line.

It also helps you you provide the error message.

Duane
Hook'D on Access
MS Access MVP
 
Hi TheAceman1

Thanks for the input but although I don't get an error it simply defaults to the MS Default message reminding the user that he/she must enter a value in the tbl_Architects_Instructions.Issue_Date field. Also I take your point dhookom. As it is TheAceman is correct the line affected was the setfocus one. I have changed this to
Code:
Me.txtIssueDate.SetFocus[code] but as I have said whilst I don't get the error the programme ignores the instruction. I just have a feeling I am trying to crack a nut with a sledgehammer.
 
Why not use the Error event procedure of the form ?

Anyway, I'd replace this:
Me(ctl.Name).Setfocus
with this:
ctl.Setfocus

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top