Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / General 1 / April 2006

Tip: Looking for answers? Try searching our database.

required textbox entry

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
fong.yang@martecgroup.com - 12 Apr 2006 14:51 GMT
I have a combo box with different types of business listed.  If a user
selects "Other" from the combo box list I want to make so that the user
is required to make an entry in a textbox on the form.  Also is there a
way to make just certain textboxes on the form required fields and if
they are skipped to display a message like " HoursOfOperation is a
required field" move the user to each required field for input? Thanks.
Tom van Stiphout - 12 Apr 2006 15:12 GMT
This type of validation can best be done in the Form_BeforeUpdate
event:
if cbo1.Value = "Other" and txt2.Value Is Null then
 Msgbox "Yo! Fill out the form!"
 txt2.SetFocus
 Cancel = True  'Important; this stops the record from being saved.
end if

-Tom.

>I have a combo box with different types of business listed.  If a user
>selects "Other" from the combo box list I want to make so that the user
>is required to make an entry in a textbox on the form.  Also is there a
>way to make just certain textboxes on the form required fields and if
>they are skipped to display a message like " HoursOfOperation is a
>required field" move the user to each required field for input? Thanks.
fong.yang@martecgroup.com - 12 Apr 2006 15:46 GMT
I have the following to time stamp changes made to the record

Private Sub Form_BeforeUpdate(Cancel As Integer)
Me!UpdatedOn = Now()
End Sub

Can I have the time stamp as well as the above validation both in the
form's before update event?

Thanks.
Bob Quintal - 13 Apr 2006 01:11 GMT
> I have the following to time stamp changes made to the record
>
[quoted text clipped - 6 lines]
>
> Thanks.

Yes you can. Just add Mr van Stiphout's code after the existing
statement and before the end sub.

Signature

Bob Quintal

PA is y I've altered my email address.

fong.yang@martecgroup.com - 13 Apr 2006 13:41 GMT
the before event now looks like this:

Private Sub Form_BeforeUpdate(Cancel As Integer)
Me!UpdatedOn = Now()
If PrimaryBusiness.Value = "Other" And PrimaryOther.Value Is Null Then
 MsgBox "Must enter type of business!!"
 PrimaryOther.SetFocus
 Cancel = True  'Important; this stops the record from being saved.
End If
End Sub

When I try to run it I get a runtime error '424' Object required.  What
does that mean? How do I get it to work? Thanks.
Bob Quintal - 13 Apr 2006 22:30 GMT
> the before event now looks like this:
>
[quoted text clipped - 12 lines]
> required.  What does that mean? How do I get it to work?
> Thanks.

Use this instead

Private Sub Form_BeforeUpdate(Cancel As Integer)
Me!UpdatedOn = Now()
If Me!PrimaryBusiness.Value = "Other" _
And isnull(Me!PrimaryOther.Value) Then
 MsgBox "Must enter type of business!!"
 Me!PrimaryOther.SetFocus
 Cancel = True  'Important; this stops the record from being
saved.
End If
End Sub

the Me! qualifiers were missing and isnull() works when
sometimes is null does not.

Signature

Bob Quintal

PA is y I've altered my email address.

fong.yang@martecgroup.com - 15 Apr 2006 18:44 GMT
I have four textbox listed on the form(DaysOfOperation, HoursStart,
HoursFinish, PrimaryOther) along with one combo box (Primary Business).
I want all of the them to require an entry before moving on to the
next record. This is what I have so far in the Before Update event of
the form:

Private Sub Form_BeforeUpdate(Cancel As Integer)
Me!UpdatedOn = Now()
If Me!PrimaryBusiness.Value = "Other" _
And IsNull(Me!PrimaryOther.Value) Then
 MsgBox "Must Enter Type Of Business!!"
 Me!PrimaryOther.SetFocus
 Cancel = True  'Important; this stops the record from being saved.
   End If
End Sub

This works to require an entry in PrimaryOther, but it still allows the
other 3 textboxes to be blank.  How can I get the other 3 to be
required as well.  Thanks.
Bob Quintal - 15 Apr 2006 22:50 GMT
> I have four textbox listed on the form(DaysOfOperation,
> HoursStart, HoursFinish, PrimaryOther) along with one combo
[quoted text clipped - 18 lines]
> allows the other 3 textboxes to be blank.  How can I get the
> other 3 to be required as well.  Thanks.

just add three similar tests (one for each field.
The second would be

If IsNull(Me!DaysOfOperation.Value) Then
 MsgBox "Must Enter Days of operation!!"
 Me!DaysOfOperation.SetFocus
 Cancel = True  
End If

The next test would start....
If IsNull(Me!HoursStart.Value) Then
......
.....

You can figure them out.

Signature

Bob Quintal

PA is y I've altered my email address.

fong.yang@martecgroup.com - 15 Apr 2006 23:33 GMT
I've added the three tests.  Still the only one that is working as a
required field is just PrimaryOther.  The other three textboxes can
still be left blank.  The three textboxes are just textboxes.  They are
not part of any combo boxes or anything.  Thanks.
Bob Quintal - 15 Apr 2006 23:49 GMT
> I've added the three tests.  Still the only one that is
> working as a required field is just PrimaryOther.  The other
> three textboxes can still be left blank.  The three textboxes
> are just textboxes.  They are not part of any combo boxes or
> anything.  Thanks.

instead of
If IsNull(Me!DaysOfOperation.Value) Then

try
If len(me!daysofoperation & "") = 0

 MsgBox "Must Enter Days of operation!!"
 Me!DaysOfOperation.SetFocus
 Cancel = True  
End If

Signature

Bob Quintal

PA is y I've altered my email address.

fong.yang@martecgroup.com - 16 Apr 2006 01:05 GMT
I get a compile error Expected: Then or go to when I enter the above
code.
Bob Quintal - 16 Apr 2006 10:54 GMT
> I get a compile error Expected: Then or go to when I enter the
> above code.

If len(me!daysofoperation & "") = 0 THEN

Please try to set your newsreader to quote what you are replying
to.

Signature

Bob Quintal

PA is y I've altered my email address.

fong.yang@martecgroup.com - 15 Apr 2006 23:33 GMT
I've added the three tests.  Still the only one that is working as a
required field is just PrimaryOther.  The other three textboxes can
still be left blank.  The three textboxes are just textboxes.  They are
not part of any combo boxes or anything.  Thanks.
fong.yang@martecgroup.com - 12 Apr 2006 15:46 GMT
I have the following to time stamp changes made to the record

Private Sub Form_BeforeUpdate(Cancel As Integer)
Me!UpdatedOn = Now()
End Sub

Can I have the time stamp as well as the above validation both in the
form's before update event?

Thanks.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.