Information Technology Knowledge Base

September 23, 2006

VB errorchecking on lostfocus event

Filed under: Visual Basic 6 — Hedwig Lodrigo @ 2:14 am

Today an error was reported by an end user of my program. They could get a crazy unstopable msgbox hell. After some investigation I found this happens when the user moves the focus from one faulty text field into another one which is also faulty. Both of these textfields have a lostfocus event. In the lostfocus event some checks are done and when they checks are positive a msgbox is shown and the focus is reset to the own textbox. Internally VB triggers a lost focus event when the user leaves the textbox. Then this lostfocus event does a setfocus on it’s own textbox. This triggers the lostfocus event of the other textbox, because by clicking on it the other textbox had the focus. The solution is simpel first do a setfocus and then show a msgbox with the error.

If Not ValidDate(Somefield.Text) Then
Somefield.SetFocus
msgBox "Some message"
End if

August 11, 2006

Rows affected by a querry in VB6?

Filed under: TSQL, Visual Basic 6 — Hedwig Lodrigo @ 9:11 pm

For some reason you would like to know how many records where affected by your sql statement called from visual basic 6. But you have no clue how to do it.

This is how you do it.

When you do a query in sql server then you can see how many rows where affected by it, because sql server fills up the @@rowcount variable.

Code:

delete from customer where name like 'A%'
print @@rowcount

If you want to return this result to a result set you can do the following:

Code:

delete from customer where name like 'A%'
select @@rowcount as affected

Then in visual basic 6:

dim newrs as ADODB.Recordset
Set newrs = rs.NextRecordset
msgbox newrs.Fields("affected")

Powered by WordPress