Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old January 29th, 2004, 05:28 PM
Authorized User
 
Join Date: Jun 2003
Location: , , .
Posts: 47
Thanks: 0
Thanked 0 Times in 0 Posts
Default validate textbox

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 With Quote
  #2 (permalink)  
Old January 29th, 2004, 05:34 PM
sal sal is offline
Friend of Wrox
 
Join Date: Oct 2003
Location: Clarksville, TN, USA.
Posts: 702
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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 With Quote
  #3 (permalink)  
Old January 29th, 2004, 05:51 PM
Authorized User
 
Join Date: Jun 2003
Location: , , .
Posts: 47
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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 With Quote
  #4 (permalink)  
Old January 29th, 2004, 06:24 PM
sal sal is offline
Friend of Wrox
 
Join Date: Oct 2003
Location: Clarksville, TN, USA.
Posts: 702
Thanks: 0
Thanked 0 Times in 0 Posts
Default

 
Quote:
quote:So if a patient appointment is from 8:00 to 8:30 then they would fill the slots with the patient name.
Quote:

Which slots?

 
Quote:
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 With Quote
  #5 (permalink)  
Old January 29th, 2004, 07:01 PM
Friend of Wrox
 
Join Date: Jul 2003
Location: Houston, Texas, USA.
Posts: 174
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Change your logic from looking for null to looking for not null and set a flag if one control has a value:

Code:
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 With Quote
  #6 (permalink)  
Old January 30th, 2004, 10:49 AM
Authorized User
 
Join Date: Jun 2003
Location: , FL, USA.
Posts: 91
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Javascript to validate a textbox abhishekkashyap27 Javascript 9 May 6th, 2008 02:41 AM
how can validate dynamic textbox field & get data alpi Classic ASP Basics 0 November 4th, 2007 02:24 PM
hi help me to write javascript to validate textbox karthikc85 XML 1 October 12th, 2006 03:12 AM
Validate two textbox one for area code and number debjanib ASP.NET 1.0 and 1.1 Professional 1 June 6th, 2006 01:00 PM



All times are GMT -4. The time now is 02:01 AM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.