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 / Forms / February 2008

Tip: Looking for answers? Try searching our database.

issue with textbox in form

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Associates - 25 Feb 2008 06:58 GMT
Hi,

I was wondering if i could get some help with the form.

I'd like to be able to take the cursor back to the text-box where there is
an error. The error may be produced because the entry data doesn't satisfy
the condition.

For example, there is a textbox called age. I have the following code

Private Sub Age_Exit(Cancel As Integer)
   If Me.Age < 20 Then
       MsgBox "The age cannot be less than 20. Please check it again"
   End If

   me.Age = "" ' Clear the box
End Sub

How do i get the cursor back to the Textbox - age? i have tried to use
.setfocus but to no avail.

Thank you in advance
Allen Browne - 25 Feb 2008 08:15 GMT
Add the line:
   Cancel = True

It might be better to use the BeforeUpdate event procedure of the control.

Signature

Allen Browne - Microsoft MVP.  Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

> I was wondering if i could get some help with the form.
>
[quoted text clipped - 16 lines]
>
> Thank you in advance
Steve Schapel - 25 Feb 2008 08:21 GMT
Associates,

As an aside, you wouldn't try to set the textbox's value to "" a
zero-length string.  This line in your code should be:
  Me.Age = Null

In any case, I am going to suggest another approach, namely to use the
Before Update event to make this check. Something like this:

Private Sub Age_BeforeUpdate(Cancel As Integer)
    If Me.Age < 20 Then
        MsgBox "The age cannot be less than 20. Please check it again"
        Cancel = True
        Me.Age.Undo
    End If
End Sub

Signature

Steve Schapel, Microsoft Access MVP

> Hi,
>
[quoted text clipped - 18 lines]
>
> Thank you in advance
 
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.