Results 1 to 4 of 4
  1. #1
    Join Date
    Nov 2005
    Posts
    20

    Unanswered: Validate a text box

    I have a txt box and i do not want it to be empty. Basically the user HAS to enter some kind of information or I do not want the next txt box to be active. I want focus to be on this txt box until the user enters a character.

    How do I do this?

    Can someone give me example of a code. I'm just getting back into programming. Thanks!

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    not use you can achieve whatyou want using a WIMP system.

    you can check if a control on a form has / has not any contenyts by placing some validation code which an be called from what ever form / control events you require. In essene Access provides various events which allow you to hook actions onto.

    does this control need to have a value to write a record, or is it a case that if there'e something in that cotnrol then you want other controls to be active?

    if the latter
    if len([mycontrol]>0) then
    'insert my code if [mycontrol] has soemthing in
    else
    'insert my code if [mycontrol] has soemthing in
    endif

    ou could place a call to that function in the forms on current event (when you navigate through the recordset), the forms before insert event, and [mycontrol](s) on change event

    the code you implment could clear out exisitng data if [mycontrol] is null, it probably should enable / disable based on the true false result.
    HTH

  3. #3
    Join Date
    Oct 2003
    Location
    Ger
    Posts
    1,969
    Provided Answers: 1
    You can use the OnExit event of the TestBox
    PHP Code:
    Private Sub txt_Box_Exit(Cancel As Integer)
      If 
    txt_Box> ="" or IsNull(txt_BoxThen
        Cancel 
    1
     End 
    If 

  4. #4
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    agree putting that in the on exit event will work, BUT only if the user actually selects that text box.

    You proabbly could put a contstraint on the column in the table defintion - not sure....

    by all means use the on exit event, I'd also suggest you place the same fucntion call into the forms before update event.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •