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

check textbox

Status
Not open for further replies.

Heita

Instructor
Jun 21, 2001
6
SE
Hi!

I have a form for the user to tipe in information. When the user closes the form I want the "close" button to check if there are fields that are filled and if so,,ask the user if he wants to save that information or not. If all the fields are empty then no msgbox will show.

this is an easy question i guess...

thanx

 
Hi!

Private Sub Form_Unload(Cancel As Integer)
if isnull(me.txtMyTextBox) then
Msgbox "You must update txtMyTextBox!"
me.txtMyTextBox.setfocus
cancel=true
end if
End Sub

Aivars
 
I don't think that is what they are looking for. I think they are wanting to lop through all the text boxes at form close and then prompt the user one time if any are blank if they want to save or discard.

I haven't done it before, but I have seen code here where someone looks through all the controls on a form and then does something. I think it has something to do with looping through the forms collection?

Try doing a search or wait and someone will have the answer Terry M. Hoey
th3856@txmail.sbc.com
While I don't mind e-mail messages, please post all questions in these forums for the benefit of all members.
 
Of course, for all controles it's needed to use other codes e.g.:

Private Sub Form_Unload(Cancel As Integer)
'Check for null values of any textbox
Cancel = not AreUpdatedAllControles(me, acTextBox)
End Sub

Public Function AreUpdatedAllControles(frm As Form, intCtlType As Integer) As Boolean
'Control Constants (intCtlType)
'acBoundObjectFrame - Bound object frame
'acCheckBox - Check box
'acComboBox - Combo box
'acCommandButton - Command button
'acCustomControl - ActiveX (custom) control
'acImage - Image
'acLabel - Label
'acLine - Line
'acListBox - List box
'acObjectFrame - Unbound object frame or chart
'acOptionButton - Option button
'acOptionGroup - Option group
'acPage - Page
'acPageBreak - Page break
'acRectangle - Rectangle
'acSubform - SubForm / SubReport
'acTabCtl - Tab
'acTextBox - Text box
'acToggleButton - Toggle button

Dim ctl As Control
Dim strMsg As String

For Each ctl In frm.Controls

If ctl.Properties("ControlType") = intCtlType Then
If IsNull(ctl) Then
If strMsg <> &quot;&quot; Then
strMsg = strMsg & &quot;; &quot;
End If
strMsg = strMsg & ctl.Name
End If
End If
Next
If strMsg = &quot;&quot; Then
AreUpdatedAllControles = True
Else
MsgBox &quot;You must update:&quot; & vbLf & strMsg & &quot;!&quot;, vbExclamation
End If

Exit_AreUpdatedAllControles:
Exit Function

End Function


Aivars

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top