954,582 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

VB6 run time error 5

Hi guys,
I have a very simple form with 2 textboxes only and a listview to display added record. Upon form load i wanted to sest focus to textbox1, but it shows this error:
Run-time error 5:Invalid Procedure call or argument

My form load code

Private Sub Form_Load()
bModelMaster = False
Call GET_LV_MODEL_MASTER
Call cmdClear_Click

End Sub
Function GET_LV_MODEL_MASTER()
Me.lvwMasterModel.ListItems.Clear
Dim lItem As ListItem
Dim rs As New ADODB.Recordset
Dim sql As String

Call ConnectDB
sql = "Select * from MODEL_MASTER"
If search = True Then
sql = sql & " where PARTNUMBER like '%" & Me.txtPartNumber.Text & "%'"
End If
rs.Open sql, DB, adOpenStatic, adLockReadOnly

With rs
Do While Not .EOF
Set lItem = Me.lvwMasterModel.ListItems.Add
lItem.SubItems(1) = rs!model_name
lItem.SubItems(2) = rs!PartNumber

.MoveNext
Loop
End With
search = False

End Function
Private Sub cmdClear_Click()
Dim Ctl As Control
    'Clear all the TextBoxes on the form
    For Each Ctl In Controls
        If TypeOf Ctl Is TextBox Then Ctl.Text = ""
    Next Ctl
    Me.txtPartNumber.SetFocus
End Sub


Please anyone help me. It's urgent :S

shena
Junior Poster in Training
57 posts since May 2009
Reputation Points: 10
Solved Threads: 0
 

Shena, I believe that the form must be fully shown for the SetFocus command of any of that form's children to work. Placing "Me.Show" in your Form_Load() on a line above your textbox1.SetFocus ought to clear that up.

Private Sub Form_Load()
	'....
	me.Show
	textbox1.SetFocus
	'....
End Sub
robert_c_guy
Newbie Poster
4 posts since Dec 2008
Reputation Points: 22
Solved Threads: 1
 

As Robert pointed out, you can only set focus o something that is visible. If your form is visible, make sure that the textbox is visible as well.

AndreRet
Senior Poster
3,922 posts since Jan 2008
Reputation Points: 334
Solved Threads: 350
 

Hi guys,

Thanks a lot for the explanations. I got the work flow now. :)

shena
Junior Poster in Training
57 posts since May 2009
Reputation Points: 10
Solved Threads: 0
 

Only a pleasure.:)

AndreRet
Senior Poster
3,922 posts since Jan 2008
Reputation Points: 334
Solved Threads: 350
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You