|
-
December 9th, 1999, 11:39 AM
#1
VB Bug ???
Hi all,
Here's my problem
Given
A Form containing
A/ a textbox (txt_Name = Name of a company)
B/ a command button (cmd_Save = Save button)
C/ a lostfocus event for this textbox (txt_Name)
private Sub LostFocus_txt_Name()
' Checks if company name is filled in
' & then enables the command buttton
cmd_Save.Enabled = false
If (len(Trim(txt_Name)) = 0) then
Exit Sub
End If
cmd_Save.Enabled = true
End Sub
Problem
You have to click 2 times on the command button to activate the
Click event on this command button !!!
Is there a solution to this problem ???
Thanks.
Jordan
-
December 9th, 1999, 02:24 PM
#2
Re: VB Bug ???
If you are using VB6 it's much better to use Validate event:
private Sub txtName_Validate(Cancel as Boolean)
If txtName.Text = "" then Cancel = true
End Sub
Actually you can use LostFocus for this particular case, but when you place at least one more control which value you need to validate when it's loosing focus you'll have hightmare.
Vlad
-
December 9th, 1999, 06:58 PM
#3
Re: VB Bug ???
It's not a bug - just a 'bad' (?) way of doing it. How about setting the enabled property in the 'change' event of the text1 textbox :
private Sub txtName_Change()
If len(Trim$(txtName.Text)) > 0 then
cmdSave.Enabled = true
else
cmdSave.Enabled = false
End If
'
' or if you want to be really clever
'
' cmdSave.Enabled = (len(Trim$(txtName.Text)) > 0)
End Sub
Either of the two methods above will work (- with all versions of VB since v3 I think)
Chris Eastwood
CodeGuru - the website for developers
http://codeguru.developer.com/vb
-
December 28th, 1999, 05:46 AM
#4
Re: VB Bug ???
hey use a global variable here goes
public i as integer
form_load()
I=0
end sub
command1_click()
if i =0 then
i=I+1
exit sub
else
* perform wot ever operations u want *
i=0 again
end if
end sub
try this code it may work!
Sudharshaan
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
|