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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

form data entry 1

Status
Not open for further replies.

Eddyoftheyear

Technical User
Aug 11, 2010
57
0
0
US
I have a form that has about 30 fields. I want to make sure that 5 fields to be mandatory to enter information in.

Name, firstname,lastname,dob,badgeID, and deptID
Some are text fields and some are comboboxes.

the form name is Staff_frm

the form is bound to the tabel. I don't want to set the field to required from the table. I just want it from the form.

your help would be appriciated!!!!!
 
How are ya Eddyoftheyear . . .
Eddyoftheyear said:
[blue]I want to make sure that 5 fields to be mandatory to enter information in.[/blue]
Validation is typically done in the forms [blue]Before Update[/blue] event ... where you can use the cancel arguement to go back if validation fails.

To start ... put a question mark [blue]?[/blue] in the [blue]Tag[/blue] property of the controls of interest ([red]no quotations please![/red]). Next ... in the forms [blue]Before Update[/blue] event, copy/paste the following:
Code:
[blue]   For Each ctl In Me.Controls
      If ctl.Tag = "?" Then
         If Trim(ctl & "") = "" Then
            MsgBox "'" & ctl.Name & "' Requires Data!", _
                   vbExclamation + vbOKOnly, _
                   "Missing Data Detected! ..."
            ctl.SetFocus
            [purple][b]Cancel[/b][/purple] = True
            Exit For
         End If
      End If
   Next[/blue]
That it ... perform your testing.

[blue]Your Thoughts? . . .[/blue]


See Ya! . . . . . .

Be sure to see faq219-2884 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
I am fine TheAceman1

Sorry for the silly question but when you say but ? in the tag property control, are you reffering to the smart tag in the data dab in design view...
 
Thank you TheAceMan1. I found the tag and worked nicely.

You guys are Awesome!!
 
Eddyoftheyear . . .

Thankyou for the star. I'd like to take you one step closer and present a little more robust ... [blue]validation![/blue] By that I mean, just typing anything in a control isn't quite enough ...

Lets say someone types two letters (only) in [blue]dob[/blue]. Surely this is not a date! ... and this needs to be checked for ... otherwise something along the line will go wrong and pump-up an error message! The code I presented is basically [blue]general[/blue] in its intent ... and will allow the two characters to pass ... simply because the field/control isn't empty. For true valiation ... this isn't enough! Data type needs to be checked as well. The following is an example of this ... I just don't know the datatype of [blue]badgeID & deptID[/blue] and am assuming their nueric ...
Code:
[blue]   Dim numCtl As String
   
   numCtl = "BadgeID;DeptID"
   
   For Each ctl In Me.Controls
      If ctl.Tag = "?" Then
         If ctl.Name = "dob" Then
            If Not IsDate(Me(ctl.Name)) Then
               MsgBox "'" & ctl.Name & "' is Not A Date!", _
                      vbExclamation + vbOKOnly, _
                      "Improper Data Entry Detected! ..."
               ctl.SetFocus
               Cancel = True
               Exit For
            End If
      ElseIf InStr(1, numCtl, ctl.Name) > 0 Then
         If Not IsNumeric(Me(ctl.Name)) Then
            MsgBox "'" & ctl.Name & "' is Not Numeric!", _
                   vbExclamation + vbOKOnly, _
                   "Improper Data Entry Detected! ..."
            ctl.SetFocus
            Cancel = True
            Exit For
         End If
      Else
         If Trim(ctl & "") = "" Then
            If Not IsDate(Me(ctl.Name)) Then
               MsgBox "'" & ctl.Name & "' is Empty!", _
                      vbExclamation + vbOKOnly, _
                      "Improper Data Entry Detected! ..."
               ctl.SetFocus
               Cancel = True
               Exit For
            End If
         End If
      End If
   Next[/blue]
Your Thoughts? . . .[/blue]

See Ya! . . . . . .

Be sure to see faq219-2884 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top