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

required fields 1

Status
Not open for further replies.

akar33

Programmer
Dec 13, 2004
39
0
0
US
I have used tab control to distribute the data fields for each records
for
e.g in each pane there are 20 data fields, I have over 4 panes like that all the data elements belong to each record.

There is one data field in each pane that is required field if the user does not complete it then the entire record should not be saved.

The user shlould get a warning message that you cannot save this record.

Please let me know How Can I acheive it.

Annie
 
You may be able use the [tt]ValidationRule()[/tt] of the required fields to get Access to prompt the user for this information. It can be a little ugly though.

Another approach would be to write a validation routine that fires [tt]BeforeInsert()[/tt] or [tt]BeforeUpdate()[/tt]. This way you can check the four fields and alert the user if any information is missing. It would look something like this (change the values in italics to match your real fields/tabs):
Code:
Public Function ValidFormData() As Boolean
Dim strValidationMessage as String
[green]'Check the first field to make sure data is entered[/green]
If Me.[i]Field1[/i] = "" Then
  strValidationMessage = "[i]Field1[/i] on [i]Tab1[/i] needs to be completed"
End If
[green]'Check the second field to make sure data is entered[/green]
If Me.[i]Field2[/i] = "" Then
  [green]'Check if a new message line needs to be added[/green]
  If Len(strValidationMessage) > 0 Then
    strValidationMessage = strValidationMessage & _
    vbCrLf & "[i]Field2[/i] on [i]Tab2[/i] needs to be completed"
  Else
    strValidationMessage = "[i]Field2[/i] on [i]Tab2[/i] needs to be completed"
  End If
End If
[green]'continue for all the fields you want to check
'...[/green]

[green]'There is a validation message so the form must not be complete[/green]
If Len(strValidationMessage) = 0 Then
  ValidFormData = Not True 'invert return value
Else
  MsgBox strValidationMessage,vbOkOnly,"Validation Error"
  ValidFormData = Not False 'invert return value
End If
End Function
You can then fire the validation routine in the appropriate routine like:
Code:
Private Sub Form_BeforeInsert(Cancel As Integer)
  Cancel = ValidateFormData
End Sub
Hope this helps,
CMP

Funny thing about being unemployed, weekends don't mean quite so much, just means you get to hang out with your working friends. Primus
 
Thanks looks like second option is a better option, should I add this code to the main forms BeforeInsert()
 
Yes. The user will then get only one message alerting them of the incomplete fields.

CMP

Funny thing about being unemployed, weekends don't mean quite so much, just means you get to hang out with your working friends. Primus
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top