|
-
Dec 24th, 2007, 12:32 PM
#1
Thread Starter
Frenzied Member
[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
-
Dec 24th, 2007, 12:38 PM
#2
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.
-
Dec 24th, 2007, 12:42 PM
#3
Thread Starter
Frenzied Member
Re: messagebox always pop up
 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
-
Dec 24th, 2007, 12:47 PM
#4
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|