We help IT Professionals succeed at work.

Displaying asterisk "*" text in required form fields

billcute
billcute asked
on
3,026 Views
Last Modified: 2013-11-28
How do I display to the user which fields are the "required" fields when they click the update or save button.  Then, the form displays the required fields, with the asterik "*" symbol next to the label or the input field to show the user that the field is required. I know there is a "Required Field Text:" option, but that is for the error message that is display next to the input field.

In other words,
(1). Use an asterisk "*" to highlight information that has been filled out incorrectly or which is compulsory.
(2). Ensure that the "*" is grouped with the text label.
(3). The "*" can be colored, in red for example, to draw attention to it as,and
(4). Making sure tat the asterik " * " only appear at the missing form fields and then disappear after
       all missing fields are completed.
Suggestions as to the design and code implementation will be appreciated.
Comment
Watch Question

change the Caption property of the Label

let say for example a Name field having label "NAME:" is required, you can put this code

Label1.Caption = "NAME:*"

to make it red

Label1.Forecolor = #ED1C24

you can put these code in your after_update event of the required field.

provided that the name of your text field is txtName, you code will look something like this

if isnull(txtName.value) then
   Label1.Caption = "NAME:*"
   Label1.Forecolor = #ED1C24
end if

Author

Commented:
antontolentino:
I currently have a working code that checks for "required field" and then will list all required fields in a message box.  If you could modify my current code to work your suggested code above, it will be great.
I'll post the code if you want.
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Application Developer
CERTIFIED EXPERT
Top Expert 2007

Commented:
An alternative thing you can do is put something like this in the Format property of a text box:

@;"<required>"   or   ;;;[Red]"<required>"

If you have a date/time field and you already have a Format, you can do this:

ddd mm-dd-yyyy;;;[Blue]"<required>"

So, whenever the control is blank, you will see the word <required> or whatever word you like.

mx

Author

Commented:
MX,
I am hoping for asterik that would only display when user clicks the "save" button and some fields are incorrectly filled or required field are missing. As I have said in my previous post to "antontolentino", I do have a working function that I would wish to convert from "msgbox" type flag  to asterik type design.

If you are wishing to help on this, it will be great.
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Application Developer
CERTIFIED EXPERT
Top Expert 2007

Commented:
Bill, I would love to help you, but there is a fair amount of complexity to get the working 'just right' ... cover all cases such that asterisks are displayed (or not) when they should be.  Unfortunately, I am really short on time today. Sorry ...

mx

Author

Commented:
mx,
Not to worry, I can understand.

Regards
Bill

Author

Commented:

I tried your suggested code dated 10/07/07. I recieved a compile error:
"variable not defined"

..on
Label1

.....from:

Private Sub txtName_AfterUpdate()
If IsNull(txtName.Value) Then
   Label1.Caption = "Name:*"
   Label1.ForeColor = "#ED1C24"   ' <<<--- I also corrected this line as shown
End If
End Sub
CERTIFIED EXPERT
Top Expert 2006
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
CERTIFIED EXPERT
Top Expert 2006
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
CERTIFIED EXPERT
Top Expert 2006
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
rockiroads,
Thank you for taken time to response to my post out of your busy schedule.

Yes, I noticed that you have not appeared on EE for awhile now but I have been posting new questions for once awhile to polish my current working code - nothing big really.

I homestly appreciate your response on this post. I read through the code - seems a little confused about the implementation - i.e the steps of implementing both "numbers" and "text" code you posted above..

Your first post was well understood - the other two followup posts seesmsomewhat confusing - may require furher explanation for me to grasp it. However, based what I have seen it's definitely waht I am looking for.
(1). I curently have: textboxes and checkboxes (radio and box type checkboxes).
(2). Some of the texboxes are numeric while others are text type boxes.
(3). I have criteria expression for some of the "required" tag fields as well such as (Case 3"ne") below.
I have decided to post my current working "Tag" functions, If you could modify these functions to work with the ones you already posted above - it will be great.
' *****************
Public Function ChkCtl(ByRef mCtl As Control) As Boolean
  ChkCtl = True
    If mCtl.Properties("TabIndex") <= Screen.ActiveControl.Properties("TabIndex") Then  ' <<--additional
       Select Case ExtractTag(mCtl.Tag, 2)   '<<-- Another function for extracting "tag"
                                                                     ***Tags are set in controls like: [ne] [1ne] or [2ne]
         Case "ne"
                If Len(Nz(mCtl.Value)) = 0 Then ChkCtl = False
         Case "1ne"
                If Len(Screen.ActiveForm.txtPermitNo) > 0 And Len(Nz(mCtl.Value)) = 0 Then ChkCtl = False
        Case "2ne"
                If Len(Screen.ActiveForm.cboSConnType) > 0 And Len(Nz(mCtl.Value)) = 0 Then ChkCtl = False
        Case "3ne"                                      '<<--- Case '3ne' is based on criteria expression
                If Len(Screen.ActiveForm.txtPermitNo) > 0 And _
                    Screen.ActiveForm.cboSConnType = "NC" And _
                    (Screen.ActiveForm.cboSewerType = "SA" Or _
                    Screen.ActiveForm.cboSewerType = "CM") And _
                    Len(Nz(mCtl.Value)) = 0 Then ChkCtl = False
        Case ">0"
                If Not Nz(mCtl.Value) > 0 Then ChkCtl = False
       Case "tf"
                If Nz(mCtl.Value, 99) <> 0 And Nz(mCtl.Value, 99) <> -1 Then ChkCtl = False
      End Select
  End If                            '<<--Additional
  Exit Function
End Function
' *************
Function MandatoryFields() As Boolean      
  Dim myCtl As Control
  Dim myCtlList As String
    MandatoryFields = True
        ' First the basic controls
            For Each myCtl In Me.Controls
                If Len(myCtl.Tag) > 1 Then
                    If ChkCtl(myCtl) = False Then
                        myCtlList = myCtlList & Me.Controls("l_" & myCtl.Name).Caption & ", "
                    On Error Resume Next
                        myCtl.Properties("BackColor") = 8454143
                    On Error GoTo 0
                Else
                    On Error Resume Next
                        myCtl.Properties("BackColor") = 16777215
                    On Error GoTo 0
                End If
            End If  
        Next
                If Len(myCtlList) > 0 Then MsgBox "Please fill the following field(s) before continuing:" & vbCrLf & myCtlList
            Exit Function
    End Function        
' ***********
Note:
You may post your amended code at your convenience. You can even combine my two functions into one - whatever you feel is more efficient will be appreciated.

Regards
Bill

Author

Commented:
rockiroads:
Please disregard my last post. I have been able to figure out your code. I put the code together per your last three posts. It works great. I really appreciate your taken time to assist with the code despite your busy schedule.

Regards
Bill

Author

Commented:
rockiroads:
I'll split your code among all your three posts.
Regards
Bill

Author

Commented:
rockiroads:
Sorry.... I meant to say that I'll split your points on your three assisted code.
Regards
Bill

Commented:
There is a simple way to modify the label associated with a text box in Access 2007 (unsure if this is true in earlier versions)

dim oLabel as Label
Set oLabel = oTextBox.Controls(0)
oLabel.caption = "New caption" <- add or remove * as required.

Author

Commented:
dlotts:
Happy New Year.
I didnt quite understand your suggestion but I can open a new post on the subject and upload a sample db to explore your method.

Regards
Bill

Commented:
In your code, you get the associated label by using a naming convension.  That will work fine but requires some maintenance to keep everything named correctly.

By changing
myCtlList = myCtlList & Me.Controls("l_" & myCtl.Name).Caption & ", "
to something like
dim oLabel as Label
Set oLabel = myCtl.Controls(0)
myCtlList = oLabel.Caption & ", "

you no longer need to enforce the naming convention.  (This assumes you always have an associated label)

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.