Results 1 to 4 of 4

Thread: [RESOLVED] messagebox always pop up

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2007
    Location
    Malaysia
    Posts
    1,370

    Resolved [RESOLVED] messagebox always pop up

    I have problem here.. I want to query. When the textbox is null then I got the messagebox twice. Why?

    Code:
    Private Sub Text2_Change()
    On Error GoTo error
    databasepetatable 'connect record table peta menggunakan modul syskod
    tablesys.Close
    tablesys.Open "Select * from peta where Kod =  '" & Text2.Text & "'", consys, adOpenDynamic, adLockOptimistic
       If Not tablesys.BOF And Not tablesys.EOF Then
       Text10.Text = tablesys.Fields("Peta").Value
       Else
       MsgBox ("Tiada Rekod dijumpai")
       Text2.Text = ""
       Text10.Text = ""
       End If
    error:
    End Sub

  2. #2
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: messagebox always pop up

    Because you are setting the textbox value again.
    1. Text2 = something
    2. It isn't in your database and you get msgbox
    3. Now you change Text2="" and the Text2_Change event fires again and msgbox happens again.

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2007
    Location
    Malaysia
    Posts
    1,370

    Re: messagebox always pop up

    Quote Originally Posted by LaVolpe
    Because you are setting the textbox value again.
    1. Text2 = something
    2. It isn't in your database and you get msgbox
    3. Now you change Text2="" and the Text2_Change event fires again and msgbox happens again.
    When Text2="" this not in the database. So how to avoid the message box again

  4. #4
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: messagebox always pop up

    Many times when I want to change a control value but not have it execute the code, I'll set its tag to something and check for that value when the event fires. Something like this:
    Code:
    Private Sub Text2_Change()
    If Text2.Tag = "ignore" Then Exit Sub ' < added IF statement
    On Error GoTo error
    databasepetatable 'connect record table peta menggunakan modul syskod
    tablesys.Close
    tablesys.Open "Select * from peta where Kod =  '" & Text2.Text & "'", consys, adOpenDynamic, adLockOptimistic
       If Not tablesys.BOF And Not tablesys.EOF Then
       Text10.Text = tablesys.Fields("Peta").Value
       Else
       MsgBox ("Tiada Rekod dijumpai")
       Text2.Tag = "ignore" ' < added Tag value
       Text2.Text = ""
       Text2.Tag = vbNullString ' < added Tag value
       Text10.Text = ""
       End If
    error:
    End Sub

Posting Permissions

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



Click Here to Expand Forum to Full Width