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

Add Group of Missing Fields Message to New Record Button. 1

Status
Not open for further replies.

roaml

Technical User
Feb 19, 2002
264
US
Hello,

I currently have the following code (gracious provided by PHV [thumbsup2]) attached to an event on a particular field that works really well.

<BEGIN CODE>
Private Sub Shift_Exit(Cancel As Integer)
If Trim(Me![Shift] & "") = "" Then
Beep
MsgBox "Please select a Shift from the items listed.", vbOKOnly, "Shift Field"
Me![Shift].SetFocus
Cancel = True
Exit Sub
End If
End Sub
<END CODE>

I would like to add the same concept to a new record button. Prior to leaving the current record, I would like the user to be prompted with a message listing the fields that were not completed.
Example: A user completes his first and last name and leaves the shift, department and group fields blank.

I would like to attach the following message to the “Add Record” button to cover all fields prior to exiting the record.
Please enter the shift, department and group information before exiting record.

Any help would be appreciated.


 
Well, are there specific controls that need to be scrutinized, or any empty fields are eligable?

If any, I would loop thru the controls collection.
Dim ctl as control, strControl as string
For each ctl in Me.Controls
if ctl.ControlType = acTextbox Then
if ctl.Value & "" = "" Then
strControl = strControl & ctl.Name & vbCrLf
End If
End If
Next

MsgBox = "Yo Bro', wuz up wi' da missing fields?" & _
vbCrLF & strControl

Or continue the same logic that PHV showed you, just adding the specific fields to be checked.

If Trim(Me![Shift] & "") = "" Then
strControl = stControl & "Shift, "
End If
If Trim(Me![Group] & "") = "" Then
strControl = stControl & "Group, "
End If
If Trim(Me![FirstName] & "") = "" Then
strControl = stControl & "FirstName, "
End If

 
Thank you Zion7! I love your prompt message (too funny).

I tried your suggestion and with some minor tweeking, it will work great!

Thanks again for your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top