2 Replies - 1619 Views - Last Post: 17 August 2012 - 06:13 AM Rate Topic: -----

#1 lancomi  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 17-August 12

trouble with setfocus on textbox

Posted 17 August 2012 - 05:18 AM

hello, please help me with my problem
this is my code

Private Sub Command1_Click()
If text1.Text = "" Or text2.Text = "" or text3.Text="" Then
MsgBox "All fields required", vbCritical, "Sorry"
    If text1.Text = "" Then text1.SetFocus
    Exit Sub
    If text2.Text = "" Then text2.SetFocus
    Exit Sub
    If text3.Text = "" Then text3.SetFocus
    Exit Sub
Else
  With rscustomer
            .AddNew
            .Fields(0) = Label6.Caption
            .Fields(1) = text1.Text
            .Fields(2) = text2.Text
            .Fields(3) = text3.Text
            .Fields(4) = Label7.Caption
            .Update
            MsgBox "New record save!", vbInformation, "Save Record"
            text1.Text = ""
            text2.Text = ""
            text3.Text = ""
            Label6.Caption = rscustomer.RecordCount + 1
    End With
End If



my problem is when text2 or text3 is blank,
it doesn't focus on the corresponding textbox
hope someone can help me, thank you

Is This A Good Question/Topic? 0
  • +

Replies To: trouble with setfocus on textbox

#2 maj3091  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 300
  • View blog
  • Posts: 1,776
  • Joined: 26-March 09

Re: trouble with setfocus on textbox

Posted 17 August 2012 - 06:06 AM

You are calling ExitSub after Textbox 1, so it will always exit after the first check.

This....
If text1.Text = "" Then text1.SetFocus
Exit Sub


Should be


If text1.Text = "" Then 
  text1.SetFocus
  Exit Sub
End if


You can only execute one statement inline after a Then, unless you group them using the If EndIf functionality.

This post has been edited by maj3091: 17 August 2012 - 06:07 AM

Was This Post Helpful? 1
  • +
  • -

#3 lancomi  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 17-August 12

Re: trouble with setfocus on textbox

Posted 17 August 2012 - 06:13 AM

thanks for your help mr.maj3091, my code is working now! again thank you :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1