ProgEvalJAA said:
[blue] ... what if I want that 12th field to appear on a report and not prevent saving of records?[/blue]
In this case the user needs to be given the choice to continue or make corrections. This can be done by modifying my message the user see's in my code. The user is given two buttons [blue]'Yes'[/blue] to continue ... [blue]'No'[/blue] to go back and edit the field with missing data. The Code works as follows (Bear in mind ... the forms [blue]Before Update[/blue] event is only triggered if you've edited a record ... new record or not and you attempt to change records by going to an alternate record ... new or not):
[ol][li]The controls with [purple]
?[/purple] in their [blue]Tag[/blue] property are parsed.[/li]
[li]If all controls have data, [blue]Completed[/blue] is set to '[blue]Y[/blue]' and you move to where you set the focus.[/li]
[li]On the 1st field that comes up empty, the user is given the message (showing duals proper). If user clicks Yes ... [blue]Completed[/blue] is set to '[blue]N[/blue]' and the event is allowed to cmplete ... saving the record & moving to where you set the focus.[/li]
[li]The user clicks '[blue]No[/blue]' and focus is set to the field in question and the event is cancelled and exited for correction to take place ... record is not yet saved![/li][/ol]
Having to display dual controls verses single added more complexity than I thought. However it works great. To install the code:
[ol][li]In the [blue]Before Update[/blue] event of the form, copy/paste the following:
Code:
[blue] Dim ctl As Control, DL As String, flgComplete As String
Dim Nam1 As String, Nam2 As String, strDuals As String, Idx As Integer
DL = vbNewLine & vbNewLine
strDuals = "DF1 DaysDF1 NADF10 DaysDF10 NADF11 DaysDF11 NA"
For Each ctl In Me.Controls
If ctl.Tag = "?" Then
If InStr(1, strDuals, ctl.Name) Then
If InStr(1, ctl.Name, " ") = 5 Then
Nam1 = Mid(ctl.Name, 1, 5) & "Days"
Nam2 = Mid(ctl.Name, 1, 5) & "NA"
Else
Nam1 = "DF1 Days"
Nam2 = "DF1 NA"
End If
Idx = MsgDF(Nam1, Nam2)
Else
Nam1 = ctl.Name
Idx = MsgDF(Nam1)
End If
If Idx = vbNo Then
Me(ctl.Name).SetFocus
Cancel = True
Exit Sub
ElseIf Idx = vbYes Then
flgComplete = "N"
Exit For
End If
End If
Next
If flgComplete = "" Then
Me!Completed = "Y"
Else
Me!Completed = flgComplete
End If[/blue]
[/li]
[li]While your in the forms code module, copy/paste the following function:
Code:
[blue]Public Function MsgDF(ByVal Name1 As String, Optional Name2) As Integer
Dim Msg As String, DL As String
DL = vbNewLine & vbNewLine
If IsMissing(Name2) Then
If Trim(Me(Name1) & "") = "" Then Msg = "No Data Entry in '" & Name1 & "'"
Else
If Trim(Me(Name1) & "") = "" And Trim(Me(Name2) & "") = "" Then Msg = "No Data Entry in '" & Name1 & "' or '" & Name2 & "'"
End If
If Msg <> "" Then
MsgDF = MsgBox(Msg & DL & _
"Press 'Yes' if this entry is complete." & DL & _
"Press 'No' to go back and make corrections.", _
vbCritical + vbYesNo, _
"Missing Data Detected! ...")
End If
End Function[/blue]
[/li]
[li]Thats it ... perform your testing![/li][/ol]
[blue]Your Thoughts? . . .[/blue]
See Ya! . . . . . .
Be sure to see thread181-473997 [blue]Worthy Reading![/blue]
![[thumbsup2] [thumbsup2] [thumbsup2]](/data/assets/smilies/thumbsup2.gif)
Also faq181-2886 [blue]Worthy Reading![/blue]
![[thumbsup2] [thumbsup2] [thumbsup2]](/data/assets/smilies/thumbsup2.gif)