|
Subject:
|
validate textbox
|
|
Posted By:
|
stoneman
|
Post Date:
|
1/29/2004 5:28:48 PM
|
I have a form that has many textboxes. I need to test that if all textboxes are Null then the record cannot be saved and if AT LEAST one textbox is not null then the record can be updated and saved.
I am using a loop but it is not working
For Each ctl In Me.Controls Select Case ctl.ControlType Case acTextBox If IsNull(ctl) Then MsgBox ("Enter a time") Exit Sub End If End Select Next ctl
Because the loop test each textbox whenever it comes to a tetxbox that is null then it exits the loop. I tried and put a Not in front of "IsNull(ctl) Then" line but it does not work.
There are 96 tetxboes on the form and I want to make sure that at least one textbox is not null before the record can be saved.
I am certain there is an short way of doing this without me having to write a long if statement for all 96 textboxes
Thanks for any help
|
|
Reply By:
|
sal
|
Reply Date:
|
1/29/2004 5:34:08 PM
|
If there are 96 text boxes, chances are not all of them are required. Your users will hate you (and so will management) if you punish them like this. Make only the most critical values required.
Sal
|
|
Reply By:
|
stoneman
|
Reply Date:
|
1/29/2004 5:51:28 PM
|
I am making an appointment calendar. Each text box has a label in incremental order 8:00, 8:10, 8:20, 8:30 etc all the way to 7:00pm. The textbox is realy a combobox where the user can select the patient name. So if a patient appointment is from 8:00 to 8:30 then they would fill the slots with the patient name.
They will not be punished because all 96 textboxes will not be filled immediately but during the course of the day. Also open slots are clearly visible on the form so it is easy to enter appointments in these slots.
I know this may not be the best way but with my limited knowledge it will work.
I hope this clarify my posting
Thanks
|
|
Reply By:
|
sal
|
Reply Date:
|
1/29/2004 6:24:44 PM
|
quote: So if a patient appointment is from 8:00 to 8:30 then they would fill the slots with the patient name.
Which slots?
quote: They will not be punished because all 96 textboxes will not be filled immediately but during the course of the day.
Then, when do they actually save the record?
Maybe your table structure needs to change. Could you show the table structure? You need to start there.
Sal
|
|
Reply By:
|
BethMoffitt
|
Reply Date:
|
1/29/2004 7:01:23 PM
|
Change your logic from looking for null to looking for not null and set a flag if one control has a value:
Dim Flag as Integer
For Each ctl In Me.Controls
Select Case ctl.ControlType
Case acTextBox
If Not IsNull(ctl) Then
Flag = True
End If
End Select
Next ctl
If Flag = True Then
'add steps here to continue to save
Else
Exit Sub
End If
Regards,
Beth M
|
|
Reply By:
|
Kenny Alligood
|
Reply Date:
|
1/30/2004 10:49:20 AM
|
It appears to work for me with this code:
Dim ctl As Control For Each ctl In Me.Controls Select Case ctl.ControlType Case acTextBox If IsNull(ctl) Then With ctl .SetFocus .BackColor = vbYellow End With MsgBox "Enter Time" Exit Sub End If End Select Next ctl
I would add this code to the click event of your form that adds the record to the database. Hope this helps....
Kenny Alligood
|